Source code: org/intabulas/sandler/elements/impl/GeneratorImpl.java
1 /**
2 * Copyright (c) 2003, Mark Lussier
3 * All rights reserved.
4 *
5 * Portions Copyright (c) 2003 by David A. Czarnecki
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 * Neither the name of the "Mark Lussier" and "Sandler" nor the names of
16 * its contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 * Products derived from this software may not be called "Sandler",
19 * nor may "Sandler" appear in their name, without prior written permission of
20 * Mark Lussier
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
26 * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
31 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36 package org.intabulas.sandler.elements.impl;
37
38 import org.intabulas.sandler.elements.AtomElement;
39 import org.intabulas.sandler.elements.Generator;
40 import org.xmlpull.v1.XmlPullParser;
41 import org.xmlpull.v1.XmlPullParserException;
42
43 import java.io.IOException;
44
45 /**
46 * GeneratorImpl
47 *
48 * @author Mark Lussier
49 * @version $Id: GeneratorImpl.java,v 1.3 2003/09/09 23:44:44 intabulas Exp $
50 */
51 public class GeneratorImpl implements Generator, AtomElement {
52
53 private String _name;
54 private String _uri;
55
56
57 public GeneratorImpl() {
58 }
59
60 /**
61 * Set'sthe human readable name of the tooklit that generated the feed
62 *
63 * @param name a String containg the Generator's Name
64 */
65 public void setName(String name) {
66 _name = name;
67 }
68
69
70 /**
71 * Returns the human readable name of the tooklit that generated the feed
72 *
73 * @return a String containing the name
74 */
75 public String getName() {
76 return _name;
77 }
78
79
80 /**
81 * Set' the URI of the toolkit that generated the feed
82 *
83 * @param uri a String containg the Generator's URI
84 */
85 public void setUri(String uri) {
86 _uri = uri;
87 }
88
89
90 /**
91 * Returns the URI of the toolkit that generated the feed
92 *
93 * @return a String containing the URI
94 */
95 public String getUri() {
96 return _uri;
97 }
98
99
100 /**
101 * Returns a string representation of the object.
102 *
103 * @return a String representation of the object.
104 */
105 public String toString() {
106 StringBuffer buffer = new StringBuffer(HTMLTAG_START).append(ELEMENT_GENERATOR).append(SPACE);
107 buffer.append(ATTRIBUTE_NAME).append("=\"").append(_name).append("\"").append(HTMLTAG_CLOSE);
108 buffer.append(_uri);
109 buffer.append(HTMLTAG_BEGIN).append(ELEMENT_GENERATOR).append(HTMLTAG_CLOSE);
110 return buffer.toString();
111 }
112
113 /**
114 * Extract relevant content from the parser stream
115 *
116 * @param parser the XML Pull Parser instabce
117 * @throws XmlPullParserException
118 */
119 public void loadDocument(XmlPullParser parser) throws XmlPullParserException {
120 try {
121 processDocumentAttributes(parser);
122 setUri(parser.nextText());
123 } catch (IOException e) {
124 e.printStackTrace();
125 }
126
127 }
128
129 /**
130 * Process the Attibutes from the Generator Tag
131 *
132 * @param parser the XML Pull Parser instabce
133 */
134 private void processDocumentAttributes(XmlPullParser parser) {
135 int attributeCount = parser.getAttributeCount();
136 for (int x = 0; x < attributeCount; x++) {
137 if (parser.getAttributeName(x).equals(ATTRIBUTE_NAME)) {
138 setName(parser.getAttributeValue(x));
139 }
140
141 }
142 }
143
144
145 }