|
javax.xml.transform.dom.DOMResult search codefetch Acts as a holder for a transformation result tree in the form of a Document Object Model (DOM) tree.
javax.xml.transform.dom.DOMSource search codefetch Acts as a holder for a transformation Source tree in the form of a Document Object Model (DOM) tree.
javax.xml.parsers.DocumentBuilder search codefetch Defines the API to obtain DOM Document instances from an XML document.
javax.xml.parsers.DocumentBuilderFactory search codefetch Defines a factory API that enables applications to obtain a parser that produces DOM object trees from XML documents.
java.beans.XMLDecoder search codefetch The XMLDecoder class is used to read XML documents created using the XMLEncoder and is used just like the ObjectInputStream.
|
|
org.omg.CORBA.LocalObject._get_domain_managers search codefetch
Throws an org.omg.CORBA.NO_IMPLEMENT exception with the message "This is a locally constrained object." This method does not ...
org.xml.sax.helpers.XMLReaderFactory.createXMLReader search codefetch
Attempt to create an XML reader from a class name.
javax.imageio.metadata.IIOMetadata.getAsTree search codefetch
Returns an XML DOM Node object that represents the root of a tree of metadata contained within this object according to the c...
org.w3c.dom.bootstrap.DOMImplementationRegistry.getDOMImplementation search codefetch
Return the first implementation that has the desired features, or null if none is found.
org.w3c.dom.bootstrap.DOMImplementationRegistry.getDOMImplementationList search codefetch
Return a list of implementations that support the desired features.
|
| Most relevant API matches shown. View All. |
![]() |
|
|
ch07-XML/src/java/com/oreilly/jent/xml/DocumentCondenser.java (134 lines)
1 package com.oreilly.jent.xml;
2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 30 import javax.xml.transform.Transformer;
31 import javax.xml.transform.TransformerFactory;
32 import javax.xml.transform.dom.DOMSource;
33 import javax.xml.transform.stream.StreamResult;
34
35 import org.w3c.dom.Document;
36 import org.w3c.dom.NamedNodeMap;
37 import org.w3c.dom.Node;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 63 Document html = null;
64 try {
65 html = db.parse("enterprisexml.html");
66 process(html);
67
68 // Use the XSLT Transformer to see the output
69 TransformerFactory tf = TransformerFactory.newInstance();
70 Transformer output = tf.newTransformer();
71 output.transform(new DOMSource(html), new StreamResult(System.out));
72 }
73 catch (Exception ex) {
Additional matches viewable in cache of ch07-XML/src/java/com/oreilly/jent/xml/DocumentCondenser.java. ch07-XML/src/java/com/oreilly/jent/xml/TreeBuilder.java (84 lines)
1 package com.oreilly.jent.xml;
2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 31 import javax.xml.transform.TransformerException;
32 import javax.xml.transform.TransformerFactory;
33 import javax.xml.transform.dom.DOMSource;
34 import javax.xml.transform.stream.StreamResult;
35
36 import org.w3c.dom.Document;
37 import org.w3c.dom.Element;
38 import org.w3c.dom.Node;
Additional matches viewable in cache of ch07-XML/src/java/com/oreilly/jent/xml/TreeBuilder.java. ch17-Ant/ex11-portable/src/java/com/oreilly/jent/people/xml/XMLPersonDAO.java (174 lines)
3 */
4 package com.oreilly.jent.people.xml;
5
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 19 import javax.xml.transform.TransformerException;
20 import javax.xml.transform.TransformerFactory;
21 import javax.xml.transform.dom.DOMSource;
22 import javax.xml.transform.stream.StreamResult;
23
24 import org.w3c.dom.DOMException;
25 import org.w3c.dom.Document;
26 import org.w3c.dom.Node;
27 import org.w3c.dom.NodeList;
28 import org.xml.sax.SAXException;
29
30 import com.oreilly.jent.people.InvalidSearchException;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 157 people.add(p);
158 }
159 catch (DOMException de) {
160 sLog.severe("XML issue while parsing people data file: " +
161 de.getMessage());
162 }
Additional matches viewable in cache of ch17-Ant/ex11-portable/src/java/com/oreilly/jent/people/xml/XMLPersonDAO.java. ch12-WebServices/src/java/com/oreilly/jent/people/xml/XMLPersonDAO.java (190 lines)
1 package com.oreilly.jent.people.xml;
2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 36 import javax.xml.parsers.DocumentBuilderFactory;
37 import javax.xml.parsers.FactoryConfigurationError;
38 import javax.xml.parsers.ParserConfigurationException;
39
40 import org.w3c.dom.DOMException;
41 import org.w3c.dom.Document;
42 import org.w3c.dom.Node;
43 import org.w3c.dom.NodeList;
44 import org.xml.sax.SAXException;
45
46 import com.oreilly.jent.people.InvalidSearchException;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 173 people.add(p);
174 }
175 catch (DOMException de) {
176 sLog.severe("XML issue while parsing people data file: " +
177 de.getMessage());
178 }
Additional matches viewable in cache of ch12-WebServices/src/java/com/oreilly/jent/people/xml/XMLPersonDAO.java. ch18-JUnitCactus/src/java/com/oreilly/jent/people/xml/XMLPersonDAO.java (195 lines)
1 package com.oreilly.jent.people.xml;
2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 36 import javax.xml.parsers.DocumentBuilderFactory;
37 import javax.xml.parsers.FactoryConfigurationError;
38 import javax.xml.parsers.ParserConfigurationException;
39
40 import org.w3c.dom.DOMException;
41 import org.w3c.dom.Document;
42 import org.w3c.dom.Node;
43 import org.w3c.dom.NodeList;
44 import org.xml.sax.SAXException;
45
46 import com.oreilly.jent.people.InvalidSearchException;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 178 people.add(p);
179 }
180 catch (DOMException de) {
181 sLog.severe("XML issue while parsing people data file: " +
182 de.getMessage());
183 }
Additional matches viewable in cache of ch18-JUnitCactus/src/java/com/oreilly/jent/people/xml/XMLPersonDAO.java. |
![]() |
|
|
jcb_package/src/jcb/util/DOM2Writer.java (467 lines)
59
60 import org.w3c.dom.Attr;
61 import org.w3c.dom.Element;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 70
71 /**
72 * This class is a utility to serialize a DOM node as XML. This class
73 * uses the <code>DOM Level 2</code> APIs.
74 * The main difference between this class and DOMWriter is that this class
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 78 * @author Joseph Kesselman
79 */
80 public class DOM2Writer
81 {
82
83 private static final char NL = '\n';
84 private static final char CR = '\r';
85
86 /**
87 * The prefered line separator
88 */
89 private static final String LS = System.getProperty(
90 "line.separator",
91 (new Character(NL)).toString());
92
93 /**
94 * The namespaceURI represented by the prefix <code>xmlns</code>.
95 */
96 private static String NS_URI_XMLNS = "http://www.w3.org/2000/xmlns/";
Additional matches viewable in cache of jcb_package/src/jcb/util/DOM2Writer.java. jcb_package/src/jcb/util/DocumentManager.java (2134 lines)
1 package jcb.util;
2
3 import org.xml.sax.InputSource;
4 import org.w3c.dom.*;
5
6
7 import javax.xml.transform.*;
8 import javax.xml.transform.dom.*;
9 import javax.xml.transform.stream.*;
10
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 13
14 import org.apache.xml.serialize.OutputFormat;
15 import org.apache.xml.serialize.XMLSerializer;
16
17 import org.jdom.transform.*;
18 import org.jdom.output.*;
19 import org.jdom.input.*;
20
21
22 import java.io.*;
23 import java.util.*;
24
25 /**
26 * This class is a utility class; it provides
27 * methods for manipulation of XML documents.
28 * <p>
29 * @author: Mahmoud Parsian
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 556 buffer.append("<simple name=\"element\" type=\"void\">void</simple>");
557 buffer.append(LIST_TAG_END);
558 return stringToDOM(buffer);
559 }
560
561 //
562 // String
563 //
564 public static String toStringXML(java.lang.String str) {
565 if (str == null) {
566 return LIST_TAG_SIMPLE_NULL;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 577
578 public static Document toDocument(java.lang.StringBuffer sb) {
579 return stringToDOM(toStringXML(sb.toString()));
580 }
581
582 public static Document toDocument(java.lang.String str) {
583 return stringToDOM(toStringXML(str));
584 }
585
586 public static Document toDocument(org.w3c.dom.Document doc) {
587 return doc;
588 }
589
590 //
591 // char and Character
592 //
593 public static String toStringXML(char input) {
594 StringBuffer buffer = new StringBuffer(LIST_TAG_BEGIN_SIMPLE_ONE_ELEMENT);
595 buffer.append("<simple name=\"element\" type=\"string\">");
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 610
611 public static Document toDocument(java.lang.Character input) {
612 return stringToDOM(toStringXML(input));
613 }
614
615 public static Document toDocument(char input) {
616 return stringToDOM(toStringXML(input));
617 }
618
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 640
641 public static Document toDocument(java.lang.Boolean input) {
642 return stringToDOM(toStringXML(input));
643 }
644
645 public static Document toDocument(boolean input) {
646 return stringToDOM(toStringXML(input));
647 }
648
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 670
671 public static Document toDocument(java.lang.Short input) {
672 return stringToDOM(toStringXML(input));
673 }
674
675 public static Document toDocument(short input) {
676 return stringToDOM(toStringXML(input));
677 }
678
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 699
700 public static Document toDocument(java.lang.Integer input) {
701 return stringToDOM(toStringXML(input));
702 }
703
704 public static Document toDocument(int input) {
705 return stringToDOM(toStringXML(input));
706 }
707
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 729
730 public static Document toDocument(java.lang.Long input) {
731 return stringToDOM(toStringXML(input));
732 }
733
734 public static Document toDocument(long input) {
735 return stringToDOM(toStringXML(input));
736 }
737
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 759
760 public static Document toDocument(java.lang.Float input) {
761 return stringToDOM(toStringXML(input));
762 }
763
Additional matches viewable in cache of jcb_package/src/jcb/util/DocumentManager.java. jcb_package/src/jcb/util/TransformUtil.java (169 lines)
5
6 import javax.xml.parsers.*;
7 import org.xml.sax.*;
8 import org.w3c.dom.*;
9
10 import javax.xml.transform.*;
11 import javax.xml.transform.dom.*;
12 import javax.xml.transform.stream.*;
13
14 /**
15 * This class provides helper methods to invoke XSLT
16 * transformations, and manipulate their output.
17 */
18 public class TransformUtil {
19
20 // Global value so it can be ref'd by the tree-adapter
21 static Document document;
22
23 static String transform(StreamSource stylesource,Document doc)
24 {
25 String transformResult = "";
26 try {
27 // Use a Transformer for output
28 TransformerFactory tFactory = TransformerFactory.newInstance();
29 Transformer transformer = tFactory.newTransformer(stylesource);
30 StringWriter out = new StringWriter();
31
32 DOMSource source = new DOMSource(doc);
33 StreamResult result = new StreamResult(out);
34
Additional matches viewable in cache of jcb_package/src/jcb/util/TransformUtil.java. jcb_package/src/jcb/util/SimpleXML.java (1263 lines)
2
3 import javax.xml.parsers.*;
4 import org.xml.sax.*;
5 import org.xml.sax.helpers.*;
6 import org.w3c.dom.*;
7 import org.w3c.dom.traversal.NodeIterator;
8 import org.apache.xpath.XPathAPI;
9 import javax.xml.transform.TransformerException;
10
11 import java.io.*;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 14 /**
15 * This class provides simple XML object for easy access. It keeps a Document object internally.
16 * During object contruction, it generates DOM tree from file or string or input stream, etc. It
17 * generates an empty Document object with default top node if input xml is not specified.
18 * It provides set of APIs to access text nodes and their attributes. The class also provides APIs
19 * to print out the XML object.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 26 * String [] children = xml.getChildren();
27 *
28 * 2. Create DOM tree from scrach *
29 * SimpleXML xml = new XML("MyTop");
30 * Node rootNode = xml.getRootNode();
31 * Node node = xml.createNode("h3");
Additional matches viewable in cache of jcb_package/src/jcb/util/SimpleXML.java. jcb_package/src/jcb/util/XMLValidator.java (333 lines)
5
6 import org.xml.sax.*;
7 import org.xml.sax.helpers.DefaultHandler;
8 import org.xml.sax.ext.LexicalHandler;
9
10 import org.w3c.dom.Document;
11 import javax.xml.parsers.SAXParserFactory;
12 import javax.xml.parsers.ParserConfigurationException;
13 import javax.xml.parsers.SAXParser;
Additional matches viewable in cache of jcb_package/src/jcb/util/XMLValidator.java. |
![]() |
|
|
source/com/apress/logging/log4j/AsyncLogging.java (52 lines)
6
7 import org.apache.log4j.*;
8 import org.apache.log4j.xml.DOMConfigurator;
9 /** This class demonstrates the asynchronous logging
10 */
source/com/apress/server/ServerComponent.java (116 lines)
3 *
4 * This class is the remote component over RMI which reads a specified
5 *XML employee data file, converts each record to an Employee object,
6 *puts them to in a java List and rturns it to the caller.
7 */
8
9 package com.apress.server;
10
11 /**
12 *
13 * @author Administrator
14 */
15 import java.rmi.server.UnicastRemoteObject;
16 import java.rmi.Naming;
17 import java.rmi.RemoteException;
18 import java.io.File;
19 import java.util.Vector;
20 import java.util.List;
21 import java.util.Iterator;
22 import java.io.IOException;
23 import org.jdom.Document;
24 import org.jdom.input.SAXBuilder;
25 import org.jdom.JDOMException;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 56 * directory. It creates a list of Employee object out of the XML data
57 * file and return it to the caller.
58 * @param docId the name of the XML document file
59 * @return the list of the Employee object
60 * @exception RemoteException in case there is a problem in reading the file
61 */
62 public List readDocument(String docId) throws RemoteException {
63 logger.entering("com.apress.server.ServerComponent", "readDocument");
64 String name= null;
65 String code=null;
66 String dept = null;
67 String age = null;
68 try {
69 //obtaining a DOM instance from the document
70 doc = builder.build(new File(docId));
71 //finding the root element
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 89 }
90 }catch(JDOMException jdome) {
91 logger.severe("Exception in parsing the XML file: "+jdome.toString());
92 }
93 logger.exiting("com.apress.server.ServerComponent", "readDocument");
Additional matches viewable in cache of source/com/apress/server/ServerComponent.java. |
![]() |
|
|
examples/ch24/PrintDOM.java (20 lines)
1 import javax.xml.parsers.*;
2 import org.xml.sax.InputSource;
3 import org.w3c.dom.*;
4 import javax.xml.transform.*;
5 import javax.xml.transform.dom.DOMSource;
6 import javax.xml.transform.stream.StreamResult;
7
8 public class PrintDOM {
9 public static void main( String [] args ) throws Exception
10 {
11 DocumentBuilder parser =
12 DocumentBuilderFactory.newInstance().newDocumentBuilder();
13 Document document = parser.parse( new InputSource("zooinventory.xml") );
14 Transformer transformer =
15 TransformerFactory.newInstance().newTransformer();
16 Source source = new DOMSource( document );
17 Result output = new StreamResult( System.out );
18 transformer.transform( source, output );
examples/ch24/XMLGrep.java (42 lines)
1 import org.w3c.dom.*;
2 import org.xml.sax.InputSource;
3 import javax.xml.xpath.*;
4 import javax.xml.transform.*;
5 import javax.xml.transform.dom.DOMSource;
6 import javax.xml.transform.stream.StreamResult;
7
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 12 Transformer transformer =
13 TransformerFactory.newInstance().newTransformer();
14 transformer.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "yes" );
15 Source source = new DOMSource( element );
16 Result output = new StreamResult( System.out );
17 transformer.transform( source, output );
Additional matches viewable in cache of examples/ch24/XMLGrep.java. examples/ch24/PrintXInclude.java (24 lines)
1 import javax.xml.parsers.*;
2 import org.xml.sax.InputSource;
3 import org.w3c.dom.*;
4 import javax.xml.transform.*;
5 import javax.xml.transform.dom.DOMSource;
6 import javax.xml.transform.stream.StreamResult;
7
8 public class PrintXInclude {
9 public static void main( String [] args ) throws Exception
10 {
11 DocumentBuilderFactory factory =
12 DocumentBuilderFactory.newInstance();
13 factory.setNamespaceAware( true );
14 factory.setXIncludeAware( true );
15 DocumentBuilder parser = factory.newDocumentBuilder();
16 System.out.println( "aware: "+parser.isXIncludeAware() );
17 Document document = parser.parse( args[0] );
18 Transformer transformer =
19 TransformerFactory.newInstance().newTransformer();
20 Source source = new DOMSource( document );
21 Result output = new StreamResult( System.out );
22 transformer.transform( source, output );
examples/ch24/TestDOM.java (33 lines)
1 import javax.xml.parsers.*;
2 import org.w3c.dom.*;
3
4 public class TestDOM
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 8 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
9 DocumentBuilder parser = factory.newDocumentBuilder();
10 Document document = parser.parse( "zooinventory.xml" );
11 Element inventory = document.getDocumentElement();
12 NodeList animals = inventory.getElementsByTagName("Animal");
13
14 System.out.println("Animals = ");
15 for( int i=0; i<animals.getLength(); i++ ) {
16 String name = DOMUtil.getSimpleElementText(
17 (Element)animals.item(i),"Name" );
18 String species = DOMUtil.getSimpleElementText(
Additional matches viewable in cache of examples/ch24/TestDOM.java. examples/ch24/TestJDOM.java (23 lines)
1 import org.jdom.*;
2 import org.jdom.input.*;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4 import java.util.*;
5
6 public class TestJDOM {
7 public static void main( String[] args ) throws Exception {
8 Document doc = new SAXBuilder().build("zooinventory.xml");
9 List animals = doc.getRootElement().getChildren("Animal");
10 System.out.println("Animals = ");
Additional matches viewable in cache of examples/ch24/TestJDOM.java. |
![]() |
|
|
Javanut5Examples/Chapter5/DOMToStream.java (46 lines)
1 import javax.xml.transform.*;
2 import javax.xml.transform.dom.*;
3 import javax.xml.transform.stream.*;
4 import javax.xml.parsers.*;
5 import org.w3c.dom.*;
6
7 public class DOMToStream {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 14 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
15 DocumentBuilder db = dbf.newDocumentBuilder();
16 // Instead of parsing an XML document, however, just create an empty
17 // document that you can build up yourself.
18 Document document = db.newDocument();
19
20 // Now build a document tree using DOM methods
21 Element book = document.createElement("book"); // Create new element
22 book.setAttribute("id", "javanut4"); // Give it an attribute
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 32
33 // Now create a TransformerFactory and use it to create a Transformer
34 // object to transform our DOM document into a stream of XML text.
35 // No arguments to newTransformer() means no XSLT stylesheet
36 TransformerFactory tf = TransformerFactory.newInstance();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 38
39 // Create the Source and Result objects for the transformation
40 DOMSource source = new DOMSource(document); // DOM document
41 StreamResult result = new StreamResult(System.out); // to XML text
42
43 // Finally, do the transformation
Javanut5Examples/Chapter5/GetSectionTitles.java (41 lines)
1 import java.io.*;
2 import javax.xml.parsers.*;
3 import org.w3c.dom.*;
4
5 public class GetSectionTitles {
6 public static void main(String[] args)
7 throws IOException, ParserConfigurationException,
8 org.xml.sax.SAXException
9 {
10 // Create a factory object for creating DOM parsers and configure it
11 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
12 factory.setIgnoringComments(true); // We want to ignore comments
Additional matches viewable in cache of Javanut5Examples/Chapter5/GetSectionTitles.java. Javanut5Examples/Chapter5/Transform.java (22 lines)
1 import java.io.*;
2 import javax.xml.transform.*;
3 import javax.xml.transform.stream.*;
4 import javax.xml.parsers.*;
5 import org.w3c.dom.*;
6
7 public class Transform {
Javanut5Examples/Chapter5/XPathEvaluator.java (33 lines)
1 import javax.xml.xpath.*;
2 import javax.xml.parsers.*;
3 import org.w3c.dom.*;
4
5 public class XPathEvaluator {
6 public static void main(String[] args)
7 throws ParserConfigurationException, XPathExpressionException,
8 org.xml.sax.SAXException, java.io.IOException
9 {
10 String documentName = args[0];
11 String expression = args[1];
12
13 // Parse the document to a DOM tree
14 // XPath can also be used with a SAX InputSource
15 DocumentBuilder parser =
Additional matches viewable in cache of Javanut5Examples/Chapter5/XPathEvaluator.java. Javanut5Examples/Chapter5/Validate.java (49 lines)
1 import javax.xml.XMLConstants;
2 import javax.xml.validation.*;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 13 // This package contains just one class of constants.
14 SchemaFactory factory =
15 SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
16
17 // Now parse the schema file to create a Schema object
18 Schema schema = null;
19 try { schema = factory.newSchema(schemaFile); }
20 catch(SAXException e) { fail(e); }
21
22 // Get a Validator object from the Schema.
23 Validator validator = schema.newValidator();
24
25 // Get a SAXSource object for the document
26 // We could use a DOMSource here as well
27 SAXSource source =
28 new SAXSource(new InputSource(new FileReader(documentFile)));
Additional matches viewable in cache of Javanut5Examples/Chapter5/Validate.java. |
![]() |
 | Source code below from:
Pro Spring
By Rob Harrop and Jan Machacek
Published 31 January, 2005
Average rating
Powells
Alibris
|
|
business/src/test/com/apress/prospring/business/TransactionTest.java (75 lines)
8
9 import org.springframework.context.ApplicationContext;
10 import org.springframework.context.support.FileSystemXmlApplicationContext;
11
12 import com.apress.prospring.domain.Entry;
13 import com.apress.prospring.domain.User;
14
15 import junit.framework.TestCase;
16
17 /**
18 * @author robh
19 */
20 public class TransactionTest extends TestCase {
21
22 private ApplicationContext getApplicationContext() {
23 String[] paths = new String[] {
24 "./business/src/resources/applicationContext-db.xml",
25 "./business/src/resources/applicationContext.xml" };
26
Additional matches viewable in cache of business/src/test/com/apress/prospring/business/TransactionTest.java. business/src/test/com/apress/prospring/business/TransactionTest2.java (84 lines)
8
9 import org.springframework.context.ConfigurableApplicationContext;
10 import org.springframework.context.support.FileSystemXmlApplicationContext;
11 import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
12
13 import com.apress.prospring.domain.Entry;
14 import com.apress.prospring.domain.User;
15
16 /**
17 * @author janm
18 */
19 public class TransactionTest2 extends AbstractDependencyInjectionSpringContextTests {
20
21 private DefaultBlogManager blogManager;
22
23 /* (non-Javadoc)
24 * @see org.springframework.test.AbstractSpringContextTests#loadContextLocations(java.lang.String[])
25 */
26 protected ConfigurableApplicationContext loadContextLocations(String[] paths) {
27 return new FileSystemXmlApplicationContext(paths);
28 }
29
Additional matches viewable in cache of business/src/test/com/apress/prospring/business/TransactionTest2.java. ch12/src/main/java/com/apress/prospring/ch12/Main.java (55 lines)
7
8 import org.springframework.context.ApplicationContext;
9 import org.springframework.context.support.ClassPathXmlApplicationContext;
10
11 import com.apress.prospring.ch12.business.AccountManager;
12 import com.apress.prospring.ch12.domain.Account;
13
14 /**
Additional matches viewable in cache of ch12/src/main/java/com/apress/prospring/ch12/Main.java. ch9/src/java/com/apress/prospring/ch9/Main.java (94 lines)
9
10 import org.springframework.context.ApplicationContext;
11 import org.springframework.context.support.ClassPathXmlApplicationContext;
12
13 import com.apress.prospring.ch9.data.CustomerDao;
14 import com.apress.prospring.ch9.data.TestDao;
15 import com.apress.prospring.ch9.domain.Customer;
16 import com.apress.prospring.ch9.domain.CustomerAddress;
17 import com.apress.prospring.ch9.domain.Permission;
Additional matches viewable in cache of ch9/src/java/com/apress/prospring/ch9/Main.java. ch10/src/java/com/apress/prospring/ch10/Main.java (93 lines)
10
11 import org.springframework.context.ApplicationContext;
12 import org.springframework.context.support.ClassPathXmlApplicationContext;
13
14 import com.apress.prospring.ch10.data.CustomerDao;
15 import com.apress.prospring.ch10.data.OrderDao;
16 import com.apress.prospring.ch10.data.TestDao;
17 import com.apress.prospring.ch10.domain.Customer;
18 import com.apress.prospring.ch10.domain.Order;
19 import com.apress.prospring.ch10.domain.Test;
Additional matches viewable in cache of ch10/src/java/com/apress/prospring/ch10/Main.java. |
![]() |
|
|
LuceneInAction/src/lia/handlingtypes/html/NekoHTMLHandler.java (105 lines)
7 import org.apache.lucene.document.Field;
8
9 import org.cyberneko.html.parsers.DOMFragmentParser;
10
11 import org.xml.sax.SAXException;
12 import org.xml.sax.InputSource;
13
14 import org.w3c.dom.Node;
15 import org.w3c.dom.NodeList;
16 import org.w3c.dom.DocumentFragment;
Additional matches viewable in cache of LuceneInAction/src/lia/handlingtypes/html/NekoHTMLHandler.java. |
![]() |
|
|
Code/Ch23/Sketcher with XML/Element.java (639 lines)
18 import java.io.ObjectInputStream;
19 import org.w3c.dom.Document;
20 import org.w3c.dom.Attr;
21
22 public abstract class Element implements Serializable {
23 public Element(Color color) {
24 this.color = color;
25 }
26
27 // Constrcutor to initialize fields from XML document
28 protected Element(org.w3c.dom.Element xmlElement) {
29 // Get the <color> element
30 org.w3c.dom.NodeList list = xmlElement.getElementsByTagName("color");
31 setElementColor((org.w3c.dom.Element)list.item(0)); // Set the color
32
33 list = xmlElement.getElementsByTagName("position"); // Get <position>
34 setElementPosition((org.w3c.dom.Element)list.item(0)); // Set the position
35
36 angle = Double.parseDouble(xmlElement.getAttribute("angle")); // Set the angle
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 78 }
79
80 // Create XML <color> element
81 protected org.w3c.dom.Element createColorElement(Document doc) {
82 org.w3c.dom.Element colorElement = doc.createElement("color");
83
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 96 }
97
98 // Create XML point-type element
99 protected org.w3c.dom.Element createPointTypeElement(Document doc,
100 String name,
101 String xValue,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 113 }
114
115 // Create XML <position> element
116 protected org.w3c.dom.Element createPositionElement(Document doc) {
117 return createPointTypeElement(doc, "position",
118 String.valueOf(position.getX()),
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 120 }
121
122 // Set element color from XML <color> element
123 protected void setElementColor(org.w3c.dom.Element colorElement) {
124 color = new Color(Integer.parseInt(colorElement.getAttribute("R")),
125 Integer.parseInt(colorElement.getAttribute("G")),
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 127 }
128
129 // Set element position from XML <position> element
130 protected void setElementPosition(org.w3c.dom.Element posElement) {
131 position = new Point();
132 position.setLocation(Double.parseDouble(posElement.getAttribute("x")),
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 154
155 // Content is <color>, <position>, <endpoint> elements. Attribute is angle.
156 public Line(org.w3c.dom.Element xmlElement) {
157 super(xmlElement);
158
159 org.w3c.dom.NodeList list = xmlElement.getElementsByTagName("endpoint");
160 org.w3c.dom.Element endpoint = (org.w3c.dom.Element)list.item(0);
161 line = new Line2D.Double(origin.x, origin.y,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 193 }
194
195 // Add XML <line> element
196 public void addElementNode(Document doc) {
197 org.w3c.dom.Element lineElement = doc.createElement("line");
198
199 // Create the angle attribute and attach it to the <line> node
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 211 }
212
213 // Create XML <endpoint> element
214 private org.w3c.dom.Element createEndpointElement(Document doc) {
215 return createPointTypeElement(doc, "endpoint",
216 String.valueOf(line.x2+position.x),
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 234
235 // Rectangle has angle attribute. Content is <color>,<position>,<bottomright>
236 public Rectangle(org.w3c.dom.Element xmlElement) {
237 super(xmlElement);
238
239 org.w3c.dom.NodeList list = xmlElement.getElementsByTagName("bottomright");
240 org.w3c.dom.Element bottomright = (org.w3c.dom.Element)list.item(0);
241 rectangle = new Rectangle2D.Double(origin.x, origin.y,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 275 }
276
277 // Add an XML <rectangle> element
278 public void addElementNode(Document doc) {
279 org.w3c.dom.Element rectElement = doc.createElement("rectangle");
280
281 // Create the angle attribute and attach it to the <rectangle> node
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 292 }
293
294 // Create XML <bottomright> element
295 private org.w3c.dom.Element createBottomrightElement(Document doc) {
296 return createPointTypeElement(doc, "bottomright",
297 String.valueOf(rectangle.width+position.x),
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 317
318 // Circle has radius, angle attributes. Content is <color>, <position>
319 public Circle(org.w3c.dom.Element xmlElement) {
320 super(xmlElement);
321
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 354 }
355
356 // Add XML <circle> element
357 public void addElementNode(Document doc) {
358 org.w3c.dom.Element circleElement = doc.createElement("circle");
359
360 // Create the radius attribute and attach it to the <circle> node
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 390
391 // Curve has angle attribute. Content is <color>, <position>, <point>+
392 public Curve(org.w3c.dom.Element xmlElement) {
393 super(xmlElement);
394
395 curve = new GeneralPath();
396 curve.moveTo(origin.x, origin.y);
397 org.w3c.dom.NodeList nodes = xmlElement.getElementsByTagName("point");
398 for(int i = 0 ; i<nodes.getLength() ; i++) {
399 curve.lineTo(
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 454 }
455
456 // Add XML <curve> element
457 public void addElementNode(Document doc) {
458 org.w3c.dom.Element curveElement = doc.createElement("curve");
459
460 // Create the angle attribute and attach it to the <curve> node
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 510 // fontstyle is "plain", "bold", "italic", or "bold-italic"
511 // <string> content is text plus <bounds>
512 public Text(org.w3c.dom.Element xmlElement) {
513 super(xmlElement);
514
515 // Get the font details
516 org.w3c.dom.NodeList list = xmlElement.getElementsByTagName("font");
517 org.w3c.dom.Element fontElement = (org.w3c.dom.Element)list.item(0);
518 String styleStr = fontElement.getAttribute("fontstyle");
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 533
534 // Get string bounds
535 list = xmlElement.getElementsByTagName("bounds");
536 org.w3c.dom.Element boundsElement = (org.w3c.dom.Element)list.item(0);
537
538 this.bounds = new java.awt.Rectangle(origin.x, origin.y,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 541
542 // Get the string
543 list = xmlElement.getElementsByTagName("string");
544 org.w3c.dom.Element string = (org.w3c.dom.Element)list.item(0);
545 list = string.getChildNodes();
546
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 575 }
576
577 // Add XML <text> element
578 public void addElementNode(Document doc) {
579 org.w3c.dom.Element textElement = doc.createElement("text");
580
581 // Create the angle attribute and attach it to the <text> node
Additional matches viewable in cache of Code/Ch23/Sketcher with XML/Element.java. Code/Ch23/Sketcher with XML/SketchFrame.java (926 lines)
30
31 import javax.xml.parsers.DocumentBuilder;
32 import javax.xml.parsers.DocumentBuilderFactory;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 455
456 // Write sketch as XML to a file
457 private void writeXMLFile(org.w3c.dom.Document doc, FileChannel channel) {
458 StringBuffer xmlDoc = new StringBuffer(
459 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 477 }
478
479 // Create DOCTYPE declaration for the XML document
480 private String getDoctypeString(org.w3c.dom.DocumentType doctype) {
481 // Create the opening string for the DOCTYPE declaration with its name
482 String str = doctype.getName();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 538
539 case Node.TEXT_NODE:
540 nodeStr.append(replaceQuotes(((org.w3c.dom.Text)node).getData()));
541 break;
542
543 default:
544 assert false;
545 }
546 return nodeStr.toString();
547 }
548
549 // Replace quotes in XML
550 public String replaceQuotes(String str) {
551 StringBuffer buf = new StringBuffer();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 739 try {
740 DocumentBuilder builder = builderFactory.newDocumentBuilder();
741 builder.setErrorHandler(new DOMErrorHandler());
742 checkForSave();
743 theApp.insertModel(createSketchModel(builder.parse(xmlFile)));
744 filename = xmlFile.getName(); // Update the file name
745 setTitle(frameTitle+xmlFile.getPath()); // Change the window title
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 752 JOptionPane.ERROR_MESSAGE);
753 e.printStackTrace(System.err);
754 } catch(org.xml.sax.SAXException e) {
755 JOptionPane.showMessageDialog(SketchFrame.this,
756 e.getMessage(),
757 "DOM Parser Error",
758 JOptionPane.ERROR_MESSAGE);
759 e.printStackTrace(System.err);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 799 }
800
801 // Error handler class for DOM parsing of an XML sketch
802 class DOMErrorHandler implements org.xml.sax.ErrorHandler {
803 public void fatalError(org.xml.sax.SAXParseException spe)
804 throws org.xml.sax.SAXException {
805 JOptionPane.showMessageDialog(SketchFrame.this,
806 "Fatal error at line "+spe.getLineNumber()
807 + "\n"+spe.getMessage(),
808 "DOM Parser Error",
809 JOptionPane.ERROR_MESSAGE);
810 throw spe;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 819 }
820
821 public void error(org.xml.sax.SAXParseException spe) {
822 JOptionPane.showMessageDialog(SketchFrame.this,
823 "Error at line "+spe.getLineNumber()
824 + "\n"+spe.getMessage(),
825 "DOM Parser Error",
826 JOptionPane.ERROR_MESSAGE);
827 }
Additional matches viewable in cache of Code/Ch23/Sketcher with XML/SketchFrame.java. Code/Ch23/Listing Elements with Attributes/TryDOM.java (125 lines)
1 import javax.xml.parsers.DocumentBuilderFactory;
2 import javax.xml.parsers.DocumentBuilder;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4 import org.xml.sax.SAXException;
5 import org.xml.sax.SAXParseException;
6 import org.xml.sax.ErrorHandler;
7 import org.w3c.dom.Node;
8 import org.w3c.dom.Text;
9 import org.w3c.dom.Document;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 22 if(args.length == 0) {
23 System.out.println("No file to process."+
24 "Usage is:\njava TryDOM \"filename\"");
25
26 System.exit(1);
27 }
28 File xmlFile = new File(args[0]);
29 DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
30 builderFactory.setNamespaceAware(true); // Set namespace aware
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 35 try {
36 builder = builderFactory.newDocumentBuilder(); // Create the parser
37 builder.setErrorHandler(new TryDOM()); //Error handler is instance of TryDOM
38
39 } catch(ParserConfigurationException e) {
40 e.printStackTrace();
41 System.exit(1);
42 }
43 Document xmlDoc = null;
44
45 try {
Additional matches viewable in cache of Code/Ch23/Listing Elements with Attributes/TryDOM.java. Code/Ch23/Sketcher with XML/SketchModel.java (86 lines)
6 import javax.swing.JOptionPane;
7 import javax.xml.parsers.DocumentBuilderFactory;
8 import javax.xml.parsers.ParserConfigurationException;
9 import org.w3c.dom.Document;
10 import org.w3c.dom.DOMImplementation;
11 import org.w3c.dom.DOMException;
Additional matches viewable in cache of Code/Ch23/Sketcher with XML/SketchModel.java. Code/Ch23/Try DOM Parsing/TryDOM.java (116 lines)
1 import javax.xml.parsers.DocumentBuilderFactory;
2 import javax.xml.parsers.DocumentBuilder;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4 import org.xml.sax.SAXException;
5 import org.xml.sax.SAXParseException;
6 import org.xml.sax.ErrorHandler;
7 import org.w3c.dom.Node;
8 import org.w3c.dom.Text;
9 import org.w3c.dom.Document;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 20 if(args.length == 0) {
21 System.out.println("No file to process."+
22 "Usage is:\njava TryDOM \"filename\"");
23
24 System.exit(1);
25 }
26 File xmlFile = new File(args[0]);
27 DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
28 builderFactory.setNamespaceAware(true); // Set namespace aware
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 33 try {
34 builder = builderFactory.newDocumentBuilder(); // Create the parser
35 builder.setErrorHandler(new TryDOM()); //Error handler is instance of TryDOM
36
37 } catch(ParserConfigurationException e) {
38 e.printStackTrace();
39 System.exit(1);
40 }
41 Document xmlDoc = null;
42
43 try {
Additional matches viewable in cache of Code/Ch23/Try DOM Parsing/TryDOM.java. |
![]() |
|
|
v2/v2ch12/XMLWriteTest/XMLWriteTest.java (228 lines)
11 import javax.swing.*;
12 import javax.xml.parsers.*;
13 import javax.xml.transform.*;
14 import javax.xml.transform.dom.*;
15 import javax.xml.transform.stream.*;
16 import org.w3c.dom.*;
17
18
Additional matches viewable in cache of v2/v2ch12/XMLWriteTest/XMLWriteTest.java. v2/v2ch12/TransformTest/TransformTest.java (106 lines)
7 import java.util.*;
8 import javax.xml.parsers.*;
9 import javax.xml.transform.*;
10 import javax.xml.transform.dom.*;
11 import javax.xml.transform.sax.*;
12 import javax.xml.transform.stream.*;
Additional matches viewable in cache of v2/v2ch12/TransformTest/TransformTest.java. v2/v2ch12/DOMTreeTest/DOMTreeTest.java (243 lines)
12 import javax.swing.tree.*;
13 import javax.xml.parsers.*;
14 import org.w3c.dom.*;
15 import org.xml.sax.*;
16
17 /**
18 This program displays an XML document as a tree.
19 */
20 public class DOMTreeTest
21 {
22 public static void main(String[] args)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 30 /**
31 This frame contains a tree that displays the contents of
32 an XML document.
33 */
34 class DOMTreeFrame extends JFrame
35 {
36 public DOMTreeFrame()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 76 return f.isDirectory() || f.getName().toLowerCase().endsWith(".xml");
77 }
78 public String getDescription() { return "XML files"; }
79 });
80 int r = chooser.showOpenDialog(this);
81 if (r != JFileChooser.APPROVE_OPTION) return;
82 File f = chooser.getSelectedFile();
83 try
84 {
85 if (builder == null)
86 {
87 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
88 builder = factory.newDocumentBuilder();
89 }
90
91 Document doc = builder.parse(f);
92 JTree tree = new JTree(new DOMTreeModel(doc));
93 tree.setCellRenderer(new DOMTreeCellRenderer());
94
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 116
117 /**
118 This tree model describes the tree structure of an XML document.
119 */
120 class DOMTreeModel implements TreeModel
121 {
122 /**
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 161
162 /**
163 This class renders an XML node.
164 */
165 class DOMTreeCellRenderer extends DefaultTreeCellRenderer
166 {
167 public Component getTreeCellRendererComponent(JTree tree, Object value,
Additional matches viewable in cache of v2/v2ch12/DOMTreeTest/DOMTreeTest.java. v2/v2ch12/GridBagTest/GridBagPane.java (247 lines)
10 import javax.swing.*;
11 import javax.xml.parsers.*;
12 import org.w3c.dom.*;
13 import org.xml.sax.*;
14
15 import org.w3c.dom.ls.*;
16 import org.w3c.dom.bootstrap.*;
17
18 /**
19 This panel uses an XML file to describe its
20 components and their grid bag layout positions.
21 */
Additional matches viewable in cache of v2/v2ch12/GridBagTest/GridBagPane.java. v2/v2ch12/XPathTest/XPathTest.java (180 lines)
10 import javax.swing.border.*;
11 import javax.xml.namespace.*;
12 import javax.xml.parsers.*;
13 import javax.xml.xpath.*;
14 import org.w3c.dom.*;
15 import org.xml.sax.*;
16
17 /**
Additional matches viewable in cache of v2/v2ch12/XPathTest/XPathTest.java. |
![]() |
|
|
Chapter08/examples/ch8/xmlview/XmlView.java (190 lines)
1 package examples.ch8.xmlview;
2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 9
10 /**
11 * This application displays an XML file. It uses JDOM (http://www.jdom.org) to
12 * parse the file.
13 */
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 175 MessageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK);
176 mb.setText("About");
177 mb.setMessage("XML View\nAn XML file viewer written in SWT"
178 + "\nUses JDOM (http://www.jdom.org/)");
179 mb.open();
180 }
Additional matches viewable in cache of Chapter08/examples/ch8/xmlview/XmlView.java. Chapter08/examples/ch8/xmlview/XmlDocument.java (55 lines)
1 package examples.ch8.xmlview;
2
3 import java.io.*;
4
5 import org.jdom.*;
6 import org.jdom.input.*;
7
8 /**
9 * This class wraps an XML file
10 */
11 public class XmlDocument {
Additional matches viewable in cache of Chapter08/examples/ch8/xmlview/XmlDocument.java. Chapter08/examples/ch8/xmlview/XmlViewTab.java (164 lines)
1 package examples.ch8.xmlview;
2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 8 import org.eclipse.swt.widgets.*;
9
10 import org.jdom.*;
11
12 /**
13 * This class contains the controls for a tab in the XmlView application
14 */
15 public class XmlViewTab extends Composite {
Additional matches viewable in cache of Chapter08/examples/ch8/xmlview/XmlViewTab.java. |
![]() |
|
|
xml/DocWriteDOM.java (64 lines)
2
3 import javax.xml.parsers.DocumentBuilder;
4 import javax.xml.parsers.DocumentBuilderFactory;
5
6 import org.w3c.dom.Document;
7 import org.w3c.dom.Node;
8
9 /** Make up and write an XML document, using DOM
10 * UPDATED FOR JAXP.
11 * @author Ian Darwin, http://www.darwinsys.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 18 Document doc = dw.makeDoc();
19
20 // Sadly, the write() method is not in the DOM spec, so we
21 // have to cast the Document to its implementing class
22 // in order to call the Write method.
23 //
24 // WARNING
25 //
26 // This code therefore depends upon the particular
27 // parser implementation.
28 //
29 ((org.apache.crimson.tree.XmlDocument)doc).write(System.out);
30 }
31
Additional matches viewable in cache of xml/DocWriteDOM.java. xml/DocWriteJDOM.java (30 lines)
1 import org.jdom.Document;
2 import org.jdom.Element;
3 import org.jdom.output.XMLOutputter;
4
5 /** Make up and write an XML document, using JDOM
6 * @author Ian Darwin, http://www.darwinsys.com/
7 * @version $Id: DocWriteJDOM.java,v 1.4 2004/02/09 03:34:10 ian Exp $
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 10
11 public static void main(String[] av) throws Exception {
12 DocWriteJDOM dw = new DocWriteJDOM();
13 Document doc = dw.makeDoc();
14 // Create an output formatter, and have it write the doc.
15 new XMLOutputter().output(doc, System.out);
16 }
17
Additional matches viewable in cache of xml/DocWriteJDOM.java. xml/JDOMLister.java (28 lines)
2
3 import org.jdom.Document;
4 import org.jdom.JDOMException;
5 import org.jdom.input.SAXBuilder;
6 import org.jdom.output.XMLOutputter;
7
8 /**
9 * List an XML file after building it into a JDOM Document.
10 * Notice it is easier than using SAX or DOM directly.
11 */
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 15 SAXBuilder b = new SAXBuilder(true); // true -> validate
16
17 // Create a JDOM document.
18 Document doc = b.build(new File("people+dtd.xml"));
19
20 // Create an output formatter, and have it write the doc.
21 new XMLOutputter().output(doc, System.out);
22 } catch (JDOMException jex) {
23 System.out.print("PARSE ERROR: " + jex.getMessage());
24 } catch (Exception ex) {
Additional matches viewable in cache of xml/JDOMLister.java. xml/XParse.java (67 lines)
2
3 import javax.xml.parsers.DocumentBuilder;
4 import javax.xml.parsers.DocumentBuilderFactory;
5
6 import org.w3c.dom.Document;
7 import org.xml.sax.SAXException;
8 import org.xml.sax.SAXParseException;
9
10 /** Parse an XML file using DOM, via JAXP.
11 * @author Ian Darwin, http://www.darwinsys.com/
12 * @version $Id: XParse.java,v 1.9 2004/03/13 23:21:04 ian Exp $
Additional matches viewable in cache of xml/XParse.java. xml/JDOMDemo.java (107 lines)
4
5 import org.jdom.Comment;
6 import org.jdom.Document;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 51 demo(jdomElement);
52
53 } catch (JDOMException e) { // indicates a well-formedness or other error
54 System.out.println(args[i] + " is not a well formed XML document.");
55 System.out.println(e.getMessage());
56 } catch (IOException ex) {
Additional matches viewable in cache of xml/JDOMDemo.java. |
![]() |
|
|
JavaExamples3/je3/xml/WebAppConfig.java (160 lines)
10 */
11 package je3.xml;
12 import java.io.*; // For reading the input file
13 import org.w3c.dom.*; // W3C DOM classes for traversing the document
14 import org.xml.sax.*; // SAX classes used for error handling by JAXP
15 import javax.xml.parsers.*; // JAXP classes for parsing
16 import javax.xml.transform.*; // For transforming a DOM tree to an XML file.
17
18 /**
19 * A WebAppConfig object is a wrapper around a DOM tree for a web.xml
20 * file. The methods of the class use the DOM API to work with the
21 * tree in various ways.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 36 // Add a new servlet name-to-class mapping to the DOM tree
37 config.addServlet("foo", "bar");
38 // And write out an XML version of the DOM tree to standard out
39 config.output(new PrintWriter(System.out));
40 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 43
44 /**
45 * This constructor method is passed an XML file. It uses the JAXP API to
46 * obtain a DOM parser, and to parse the file into a DOM Document object,
47 * which is used by the remaining methods of the class.
48 **/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 59
60 // Tell the parser how to handle errors. Note that in the JAXP API,
61 // DOM parsers rely on the SAX API for error handling
62 parser.setErrorHandler(new org.xml.sax.ErrorHandler() {
63 public void warning(SAXParseException e) {
64 System.err.println("WARNING: " + e.getMessage());
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 146
147 /**
148 * Output the DOM tree to the specified stream as an XML document.
149 * See the XMLDocumentWriter example for the details.
150 **/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 155 Transformer transformer = factory.newTransformer();
156
157 transformer.transform(new javax.xml.transform.dom.DOMSource(document),
158 new javax.xml.transform.stream.StreamResult(out));
159 }
Additional matches viewable in cache of JavaExamples3/je3/xml/WebAppConfig.java. JavaExamples3/je3/xml/XSLTransform.java (36 lines)
10 */
11 package je3.xml;
12 import java.io.*;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 22 // Set up streams for input, stylesheet, and output.
23 // These do not have to come from or go to files. We can also use the
24 // javax.xml.transform.{dom,sax} packages use DOM trees and streams of
25 // SAX events as sources and sinks for documents and stylesheets.
26 StreamSource input = new StreamSource(new File(args[0]));
Additional matches viewable in cache of JavaExamples3/je3/xml/XSLTransform.java. |
![]() |
|
|
jservlet2-examples/ch17/HelloManipulation.java (34 lines)
1 import java.io.*;
2 import org.w3c.dom.*;
3 import org.w3c.dom.html.*;
4
5 import org.enhydra.xml.io.DOMFormatter;
6
7 public class HelloManipulation {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 15 Hello hello = new Hello();
16
17 // Set the title, using a standard DOM method
18 hello.setTitle("Hello XMLC!");
19
20 // Set the value for "greeting"
Additional matches viewable in cache of jservlet2-examples/ch17/HelloManipulation.java. jservlet2-examples/ch17/SnoopManipulation.java (47 lines)
5
6 import org.w3c.dom.*;
7 import org.w3c.dom.html.*;
8
9 import org.enhydra.xml.io.DOMFormatter;
10
11 public class SnoopManipulation extends HttpServlet {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 19 Enumeration locales = req.getLocales();
20
21 // Create the DOM tree
22 Snoop snoop = new Snoop();
23
24 // Get the first "prototype" list item
25 // The rest were removed during the xmlc compile
26 HTMLLIElement item = snoop.getElementLocale();
27
Additional matches viewable in cache of jservlet2-examples/ch17/SnoopManipulation.java. jservlet2-examples/ch17/ToolViewServlet.java (98 lines)
5
6 import org.w3c.dom.*;
7 import org.w3c.dom.html.*;
8
9 import org.enhydra.xml.io.DOMFormatter;
10
11 public class ToolViewServlet extends HttpServlet {
Additional matches viewable in cache of jservlet2-examples/ch17/ToolViewServlet.java. jservlet2-examples/ch14/Tool.java (76 lines)
3 import java.util.*;
4 import org.jdom.*;
5 import org.jdom.input.*;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 48
49 public static Tool[] loadTools(String toolsFile) throws Exception {
50 // Read the tool data from an XML file containing <tool> elements
51 // Use the JDOM API to keep things simple (http://jdom.org)
52 List toolObjects = new LinkedList();
53
jservlet2-examples/ch15/Tool.java (76 lines)
3 import java.util.*;
4 import org.jdom.*;
5 import org.jdom.input.*;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 48
49 public static Tool[] loadTools(String toolsFile) throws Exception {
50 // Read the tool data from an XML file containing <tool> elements
51 // Use the JDOM API to keep things simple (http://jdom.org)
52 List toolObjects = new LinkedList();
53
|
![]() |
|
|
JavaExamples2/com/davidflanagan/examples/xml/DOMTreeWalkerTreeModel.java (158 lines)
8 * visit http://www.davidflanagan.com/javaexamples2.
9 */
10 package com.davidflanagan.examples.xml;
11 import org.w3c.dom.*; // Core DOM classes
12 import org.w3c.dom.traversal.*; // TreeWalker and related DOM classes
13 import org.apache.xerces.parsers.*; // Apache Xerces parser classes
14 import org.xml.sax.*; // Xerces DOM parser uses some SAX classes
15 import javax.swing.*; // Swing classes
16 import javax.swing.tree.*; // TreeModel and related classes
17 import javax.swing.event.*; // Tree-related event classes
18 import java.io.*; // For reading the input XML file
19
20 /**
21 * This class implements the Swing TreeModel interface so that the DOM tree
22 * returned by a TreeWalker can be displayed in a JTree component.
23 **/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 107 // Note that we are not using the JAXP API here, so this
108 // code uses Apache Xerces APIs that are not standards
109 DOMParser parser = new org.apache.xerces.parsers.DOMParser();
110
111 // Get a java.io.Reader for the input XML file and
112 // wrap the input file in a SAX input source
113 Reader in = new BufferedReader(new FileReader(args[0]));
114 InputSource input = new org.xml.sax.InputSource(in);
115
116 // Tell the Xerces parser to parse the input source
117 parser.parse(input);
118
119 // Ask the parser to give us our DOM Document. Once we've got the DOM
120 // tree, we don't have to use the Apache Xerces APIs any more; from
121 // here on, we use the standard DOM APIs
Additional matches viewable in cache of JavaExamples2/com/davidflanagan/examples/xml/DOMTreeWalkerTreeModel.java. JavaExamples2/com/davidflanagan/examples/xml/WebAppConfig.java (153 lines)
9 */
10 package com.davidflanagan.examples.xml;
11 import javax.xml.parsers.*; // JAXP classes for parsing
12 import org.w3c.dom.*; // W3C DOM classes for traversing the document
13 import org.xml.sax.*; // SAX classes used for error handling by JAXP
14 import java.io.*; // For reading the input file
15
16 /**
17 * A WebAppConfig object is a wrapper around a DOM tree for a web.xml
18 * file. The methods of the class use the DOM API to work with the
19 * tree in various ways.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 33 // Add a new servlet name-to-class mapping to the DOM tree
34 config.addServlet("foo", "bar");
35 // And write out an XML version of the DOM tree to standard out
36 config.output(new PrintWriter(new OutputStreamWriter(System.out)));
37 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 40
41 /**
42 * This constructor method is passed an XML file. It uses the JAXP API to
43 * obtain a DOM parser, and to parse the file into a DOM Document object,
44 * which is used by the remaining methods of the class.
45 **/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 56
57 // Tell the parser how to handle errors. Note that in the JAXP API,
58 // DOM parsers rely on the SAX API for error handling
59 parser.setErrorHandler(new org.xml.sax.ErrorHandler() {
60 public void warning(SAXParseException e) {
61 System.err.println("WARNING: " + e.getMessage());
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 143
144 /**
145 * Output the DOM tree to the specified stream as an XML document.
146 * See the XMLDocumentWriter example for the details.
147 **/
Additional matches viewable in cache of JavaExamples2/com/davidflanagan/examples/xml/WebAppConfig.java. JavaExamples2/com/davidflanagan/examples/xml/WebAppConfig2.java (121 lines)
8 * visit http://www.davidflanagan.com/javaexamples2.
9 */
10 package com.davidflanagan.examples.xml;
11 import java.io.*;
12 import java.util.*;
13 import org.jdom.*;
14 import org.jdom.input.SAXBuilder;
15 import org.jdom.output.XMLOutputter;
16
17 /**
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 22 /** The main method creates and demonstrates a WebAppConfig2 object */
23 public static void main(String[] args)
24 throws IOException, JDOMException
25 {
26 // Create a new WebAppConfig object that represents the web.xml
27 // file specified by the first command-line argument
28 WebAppConfig2 config = new WebAppConfig2(new File(args[0]));
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 36 config.addServlet("foo", "bar");
37
38 // And write out an XML version of the DOM tree to standard out
39 config.output(System.out);
40 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 109
110 /**
111 * Output the JDOM tree to the specified stream as an XML document.
112 **/
113 public void output(OutputStream out) throws IOException {
114 // JDOM can output JDOM trees in a variety of ways (such as converting
115 // them to DOM trees or SAX event streams). Here we use an "outputter"
116 // that converts a JDOM tree to an XML document
117 XMLOutputter outputter = new XMLOutputter(" ", // indentation
118 true); // use newlines
Additional matches viewable in cache of JavaExamples2/com/davidflanagan/examples/xml/WebAppConfig2.java. JavaExamples2/com/davidflanagan/examples/xml/XMLDocumentWriter.java (132 lines)
8 * visit http://www.davidflanagan.com/javaexamples2.
9 */
10 package com.davidflanagan.examples.xml;
11 import org.w3c.dom.*; // W3C DOM classes for traversing the document
12 import java.io.*;
13
14 /**
15 * Output a DOM Level 1 Document object to a java.io.PrintWriter as a simple
16 * XML document. This class does not handle every type of DOM node, and it
17 * doesn't deal with all the details of XML like DTDs, character encodings and
18 * preserved and ignored whitespace. However, it does output basic
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 23
24 /** Initialize the output stream */
25 public XMLDocumentWriter(PrintWriter out) { this.out = out; }
26
27 /** Close the output stream. */
28 public void close() { out.close(); }
29
30 /** Output a DOM Node (such as a Document) to the output stream */
31 public void write(Node node) { write(node, ""); }
32
33 /**
34 * Output the specified DOM Node object, printing it using the specified
35 * indentation string
36 **/
37 public void write(Node node, String indent) {
38 // The output depends on the type of the node
39 switch(node.getNodeType()) {
40 case Node.DOCUMENT_NODE: { // If its a Document node
41 Document doc = (Document)node;
42 out.println(indent + "<?xml version='1.0'?>"); // Output header
43 Node child = doc.getFirstChild(); // Get the first node
44 while(child != null) { // Loop 'till no more nodes
Additional matches viewable in cache of JavaExamples2/com/davidflanagan/examples/xml/XMLDocumentWriter.java. |
![]() |
|
|
examples/chapter3/GuestBookServlet.java (395 lines)
13 import java.util.Properties;
14 import java.util.Random;
15 import java.util.StringTokenizer;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 27 private String jdbcURL = null;
28 private Random random = new Random();
29
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 67 * Performs the HTTP GET. This is where we print out a form and
68 * a random sample of the comments.
69 * @param req the servlet request information
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 285 rows = results.getRow();
286 // pick a random row
287 rows = random.nextInt()%rows;
288 if( rows < 4 ) {
289 // if the random row is less than 4, print the first 4 rows
290 results.afterLast();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 296 count = 0;
297 // print up to 5 rows going backwards from the randomly
298 // selected row
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 321 fmt.format(date) + "</dt>");
322 cmt = noXML(cmt);
323 out.println("<dd> " + cmt + "</dd>");
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 338 /**
339 * Removes any XML-sensitive characters from a comment and
340 * replaces them with their character entities.
341 * @param cmt the raw comment
342 * @return the XML-safe comment
343 */
344 private String noXML(String cmt) {
345 StringBuffer buff = new StringBuffer();
|
|
|