1 /**
2 * JSpiff
3 * -----------------
4 * Copyright (c) 2005-2006 Emil A. Lefkof III
5 *
6 * I always give it my best shot to make a program useful and solid, but
7 * remeber that there is absolutely no warranty for using this program as
8 * stated in the following terms:
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22 package com.melloware.jspiff.jaxp;
23
24 import java.io.File;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.io.PrintWriter;
28 import java.io.Reader;
29 import java.io.Writer;
30 import java.net.URL;
31
32 import javax.xml.parsers.ParserConfigurationException;
33
34 import org.w3c.dom.Document;
35 import org.w3c.dom.Element;
36 import org.w3c.dom.Node;
37 import org.xml.sax.InputSource;
38 import org.xml.sax.SAXException;
39
40 /**
41 * <b>XspfExtensionAnyElement</b> is generated from xspf.rng by Relaxer.
42 * This class is derived from:
43 *
44 * <!-- for programmer
45 * <element>
46 * <anyName/>
47 * <ref name="anything"/>
48 * </element>-->
49 * <!-- for javadoc -->
50 * <pre> <element>
51 * <anyName/>
52 * <ref name="anything"/>
53 * </element></pre>
54 *
55 * @version xspf.rng (Wed Sep 27 17:36:25 EDT 2006)
56 * @author Relaxer 1.1b (http://www.relaxer.org)
57 * @author Emil A. Lefkof III <info@melloware.com>
58 */
59 public class XspfExtensionAnyElement
60 implements java.io.Serializable,
61 Cloneable,
62 IXspfExtensionMixed,
63 IXspfExtensionMixedChoice {
64
65 private static RNameClass $nameClass$ = new RNameClass("<anyName></anyName>");
66
67 private java.util.List content_ = new java.util.ArrayList();
68 private String $localName$ = "extensionAnyElement";
69
70 /**
71 * Creates a <code>XspfExtensionAnyElement</code>.
72 *
73 */
74 public XspfExtensionAnyElement() {
75 }
76
77 /**
78 * Creates a <code>XspfExtensionAnyElement</code>.
79 *
80 * @param source
81 */
82 public XspfExtensionAnyElement(XspfExtensionAnyElement source) {
83 setup(source);
84 }
85
86 /**
87 * Creates a <code>XspfExtensionAnyElement</code> by the Stack <code>stack</code>
88 * that contains Elements.
89 * This constructor is supposed to be used internally
90 * by the Relaxer system.
91 *
92 * @param stack
93 */
94 public XspfExtensionAnyElement(RStack stack) {
95 setup(stack);
96 }
97
98 /**
99 * Creates a <code>XspfExtensionAnyElement</code> by the Document <code>doc</code>.
100 *
101 * @param doc
102 */
103 public XspfExtensionAnyElement(Document doc) {
104 setup(doc.getDocumentElement());
105 }
106
107 /**
108 * Creates a <code>XspfExtensionAnyElement</code> by the Element <code>element</code>.
109 *
110 * @param element
111 */
112 public XspfExtensionAnyElement(Element element) {
113 setup(element);
114 }
115
116 /**
117 * Creates a <code>XspfExtensionAnyElement</code> by the File <code>file</code>.
118 *
119 * @param file
120 * @exception IOException
121 * @exception SAXException
122 * @exception ParserConfigurationException
123 */
124 public XspfExtensionAnyElement(File file)
125 throws IOException, SAXException, ParserConfigurationException {
126 setup(file);
127 }
128
129 /**
130 * Creates a <code>XspfExtensionAnyElement</code>
131 * by the String representation of URI <code>uri</code>.
132 *
133 * @param uri
134 * @exception IOException
135 * @exception SAXException
136 * @exception ParserConfigurationException
137 */
138 public XspfExtensionAnyElement(String uri)
139 throws IOException, SAXException, ParserConfigurationException {
140 setup(uri);
141 }
142
143 /**
144 * Creates a <code>XspfExtensionAnyElement</code> by the URL <code>url</code>.
145 *
146 * @param url
147 * @exception IOException
148 * @exception SAXException
149 * @exception ParserConfigurationException
150 */
151 public XspfExtensionAnyElement(URL url)
152 throws IOException, SAXException, ParserConfigurationException {
153 setup(url);
154 }
155
156 /**
157 * Creates a <code>XspfExtensionAnyElement</code> by the InputStream <code>in</code>.
158 *
159 * @param in
160 * @exception IOException
161 * @exception SAXException
162 * @exception ParserConfigurationException
163 */
164 public XspfExtensionAnyElement(InputStream in)
165 throws IOException, SAXException, ParserConfigurationException {
166 setup(in);
167 }
168
169 /**
170 * Creates a <code>XspfExtensionAnyElement</code> by the InputSource <code>is</code>.
171 *
172 * @param is
173 * @exception IOException
174 * @exception SAXException
175 * @exception ParserConfigurationException
176 */
177 public XspfExtensionAnyElement(InputSource is)
178 throws IOException, SAXException, ParserConfigurationException {
179 setup(is);
180 }
181
182 /**
183 * Creates a <code>XspfExtensionAnyElement</code> by the Reader <code>reader</code>.
184 *
185 * @param reader
186 * @exception IOException
187 * @exception SAXException
188 * @exception ParserConfigurationException
189 */
190 public XspfExtensionAnyElement(Reader reader)
191 throws IOException, SAXException, ParserConfigurationException {
192 setup(reader);
193 }
194
195 /**
196 * Tests if a Element <code>element</code> is valid
197 * for the <code>XspfExtensionAnyElement</code>.
198 *
199 * @param element
200 * @return boolean
201 */
202 public static boolean isMatch(Element element) {
203 if (!$nameClass$.isMatchElement(element)) {
204 return (false);
205 }
206 RStack target = new RStack(element);
207 if (RString.isMatch(target)) {
208 ;
209 }
210 while (true) {
211 if (XspfAnythingAnyAttr.isMatchHungry(target)) {
212 ;
213 } else if (XspfAnythingAnyElement.isMatchHungry(target)) {
214 ;
215 } else {
216 break;
217 }
218 }
219 if (!target.isEmptyElement()) {
220 return (false);
221 }
222 return (true);
223 }
224
225 /**
226 * Tests if elements contained in a Stack <code>stack</code>
227 * is valid for the <code>XspfExtensionAnyElement</code>.
228 * This mehtod is supposed to be used internally
229 * by the Relaxer system.
230 *
231 * @param stack
232 * @return boolean
233 */
234 public static boolean isMatch(RStack stack) {
235 Element element = stack.peekElement();
236 if (element == null) {
237 return (false);
238 }
239 return (isMatch(element));
240 }
241
242 /**
243 * Tests if elements contained in a Stack <code>stack</code>
244 * is valid for the <code>XspfExtensionAnyElement</code>.
245 * This method consumes the stack contents during matching operation.
246 * This mehtod is supposed to be used internally
247 * by the Relaxer system.
248 *
249 * @param stack
250 * @return boolean
251 */
252 public static boolean isMatchHungry(RStack stack) {
253 Element element = stack.peekElement();
254 if (element == null) {
255 return (false);
256 }
257 if (isMatch(element)) {
258 stack.popElement();
259 return (true);
260 } else {
261 return (false);
262 }
263 }
264
265 /**
266 * Gets the IXspfAnythingMixed property <b>content</b>.
267 *
268 * @return IXspfAnythingMixed[]
269 */
270 public IXspfAnythingMixed[] getContent() {
271 IXspfAnythingMixed[] array = new IXspfAnythingMixed[content_.size()];
272 return ((IXspfAnythingMixed[])content_.toArray(array));
273 }
274
275 /**
276 * Gets the IXspfAnythingMixed property <b>content</b> by index.
277 *
278 * @param index
279 * @return IXspfAnythingMixed
280 */
281 public IXspfAnythingMixed getContent(int index) {
282 return ((IXspfAnythingMixed)content_.get(index));
283 }
284
285 /**
286 * Sets a mixed content by <code>String</code>.
287 *
288 * @param value
289 */
290 public void setContent(String value) {
291 setContent(new RString(value));
292 }
293
294 /**
295 * Sets a mixed content by <code>org.w3c.dom.Node</code>.
296 *
297 * @param value
298 */
299 public void setContent(org.w3c.dom.Node value) {
300 setContent(new RString(value));
301 }
302
303 /**
304 * Sets the IXspfAnythingMixed property <b>content</b>.
305 *
306 * @param content
307 */
308 public void setContent(IXspfAnythingMixed[] content) {
309 this.content_.clear();
310 for (int i = 0; i < content.length; i++) {
311 addContent(content[i]);
312 }
313 }
314
315 /**
316 * Sets the IXspfAnythingMixed property <b>content</b>.
317 *
318 * @param content
319 */
320 public void setContent(IXspfAnythingMixed content) {
321 this.content_.clear();
322 addContent(content);
323 }
324
325 /**
326 * Sets the IXspfAnythingMixed property <b>content</b> by index.
327 *
328 * @param index
329 * @param content
330 */
331 public void setContent(int index, IXspfAnythingMixed content) {
332 this.content_.set(index, content);
333 }
334
335 /**
336 * Sets a mixed content by <code>String</code>.
337 *
338 * @param value
339 */
340 public void setContentByString(String value) {
341 setContent(new RString(value));
342 }
343
344 /**
345 * Adds a mixed content by <code>String</code>.
346 *
347 * @param value
348 */
349 public void addContent(String value) {
350 addContent(new RString(value));
351 }
352
353 /**
354 * Adds a mixed content by <code>org.w3c.dom.Node</code>.
355 *
356 * @param value
357 */
358 public void addContent(org.w3c.dom.Node value) {
359 addContent(new RString(value));
360 }
361
362 /**
363 * Adds the IXspfAnythingMixed property <b>content</b>.
364 *
365 * @param content
366 */
367 public void addContent(IXspfAnythingMixed content) {
368 this.content_.add(content);
369 }
370
371 /**
372 * Adds the IXspfAnythingMixed property <b>content</b>.
373 *
374 * @param content
375 */
376 public void addContent(IXspfAnythingMixed[] content) {
377 for (int i = 0; i < content.length; i++) {
378 addContent(content[i]);
379 }
380 }
381
382 /**
383 * Adds the IXspfAnythingMixed property <b>content</b> by index.
384 *
385 * @param index
386 * @param content
387 */
388 public void addContent(int index, IXspfAnythingMixed content) {
389 this.content_.add(index, content);
390 }
391
392 /**
393 * Adds a mixed content by <code>String</code>.
394 *
395 * @param value
396 */
397 public void addContentByString(String value) {
398 addContent(new RString(value));
399 }
400
401 /**
402 * Clear the IXspfAnythingMixed property <b>content</b>.
403 *
404 */
405 public void clearContent() {
406 this.content_.clear();
407 }
408
409 /**
410 * @return Object
411 */
412 public Object clone() {
413 return (new XspfExtensionAnyElement((XspfExtensionAnyElement)this));
414 }
415
416 /**
417 * Creates a DOM document representation of the object.
418 *
419 * @exception ParserConfigurationException
420 * @return Document
421 */
422 public Document makeDocument()
423 throws ParserConfigurationException {
424 Document doc = UJAXP.makeDocument();
425 makeElement(doc);
426 return (doc);
427 }
428
429 /**
430 * Creates a DOM representation of the object.
431 * Result is appended to the Node <code>parent</code>.
432 *
433 * @param parent
434 */
435 public void makeElement(Node parent) {
436 Document doc;
437 if (parent instanceof Document) {
438 doc = (Document)parent;
439 } else {
440 doc = parent.getOwnerDocument();
441 }
442 Element element = doc.createElement($localName$);
443 if (parent instanceof Document) {
444 element.setAttribute("xmlns", "http://xspf.org/ns/0/");
445 }
446 int size;
447 size = this.content_.size();
448 for (int i = 0; i < size; i++) {
449 IXspfAnythingMixed value = (IXspfAnythingMixed)this.content_.get(i);
450 value.makeElement(element);
451 }
452 parent.appendChild(element);
453 }
454
455 /**
456 * Makes an XML text representation.
457 *
458 * @param buffer
459 */
460 public void makeTextAttribute(StringBuffer buffer) {
461 }
462
463 /**
464 * Makes an XML text representation.
465 *
466 * @param buffer
467 * @exception IOException
468 */
469 public void makeTextAttribute(Writer buffer)
470 throws IOException {
471 }
472
473 /**
474 * Makes an XML text representation.
475 *
476 * @param buffer
477 */
478 public void makeTextAttribute(PrintWriter buffer) {
479 }
480
481 /**
482 * Makes an XML text representation.
483 *
484 * @return String
485 */
486 public String makeTextDocument() {
487 StringBuffer buffer = new StringBuffer();
488 makeTextElement(buffer);
489 return (new String(buffer));
490 }
491
492 /**
493 * Makes an XML text representation.
494 *
495 * @param buffer
496 */
497 public void makeTextElement(StringBuffer buffer) {
498 int size;
499 buffer.append("<");
500 buffer.append($localName$);
501 buffer.append(" xmlns=\"http://xspf.org/ns/0/\"");
502 size = this.content_.size();
503 for (int i = 0; i < size; i++) {
504 IXspfAnythingMixed value = (IXspfAnythingMixed)this.content_.get(i);
505 value.makeTextAttribute(buffer);
506 }
507 buffer.append(">");
508 size = this.content_.size();
509 for (int i = 0; i < size; i++) {
510 IXspfAnythingMixed value = (IXspfAnythingMixed)this.content_.get(i);
511 value.makeTextElement(buffer);
512 }
513 buffer.append("</");
514 buffer.append($localName$);
515 buffer.append(">");
516 }
517
518 /**
519 * Makes an XML text representation.
520 *
521 * @param buffer
522 * @exception IOException
523 */
524 public void makeTextElement(Writer buffer)
525 throws IOException {
526 int size;
527 buffer.write("<");
528 buffer.write($localName$);
529 buffer.write(" xmlns=\"http://xspf.org/ns/0/\"");
530 size = this.content_.size();
531 for (int i = 0; i < size; i++) {
532 IXspfAnythingMixed value = (IXspfAnythingMixed)this.content_.get(i);
533 value.makeTextAttribute(buffer);
534 }
535 buffer.write(">");
536 size = this.content_.size();
537 for (int i = 0; i < size; i++) {
538 IXspfAnythingMixed value = (IXspfAnythingMixed)this.content_.get(i);
539 value.makeTextElement(buffer);
540 }
541 buffer.write("</");
542 buffer.write($localName$);
543 buffer.write(">");
544 }
545
546 /**
547 * Makes an XML text representation.
548 *
549 * @param buffer
550 */
551 public void makeTextElement(PrintWriter buffer) {
552 int size;
553 buffer.print("<");
554 buffer.print($localName$);
555 buffer.print(" xmlns=\"http://xspf.org/ns/0/\"");
556 size = this.content_.size();
557 for (int i = 0; i < size; i++) {
558 IXspfAnythingMixed value = (IXspfAnythingMixed)this.content_.get(i);
559 value.makeTextAttribute(buffer);
560 }
561 buffer.print(">");
562 size = this.content_.size();
563 for (int i = 0; i < size; i++) {
564 IXspfAnythingMixed value = (IXspfAnythingMixed)this.content_.get(i);
565 value.makeTextElement(buffer);
566 }
567 buffer.print("</");
568 buffer.print($localName$);
569 buffer.print(">");
570 }
571
572 /**
573 * Remove the IXspfAnythingMixed property <b>content</b> by index.
574 *
575 * @param index
576 */
577 public void removeContent(int index) {
578 this.content_.remove(index);
579 }
580
581 /**
582 * Remove the IXspfAnythingMixed property <b>content</b> by object.
583 *
584 * @param content
585 */
586 public void removeContent(IXspfAnythingMixed content) {
587 this.content_.remove(content);
588 }
589
590 /**
591 * Initializes the <code>XspfExtensionAnyElement</code> by the XspfExtensionAnyElement <code>source</code>.
592 *
593 * @param source
594 */
595 public void setup(XspfExtensionAnyElement source) {
596 int size;
597 this.content_.clear();
598 size = source.content_.size();
599 for (int i = 0; i < size; i++) {
600 addContent((IXspfAnythingMixed)source.getContent(i).clone());
601 }
602 }
603
604 /**
605 * Initializes the <code>XspfExtensionAnyElement</code> by the Document <code>doc</code>.
606 *
607 * @param doc
608 */
609 public void setup(Document doc) {
610 setup(doc.getDocumentElement());
611 }
612
613 /**
614 * Initializes the <code>XspfExtensionAnyElement</code> by the Element <code>element</code>.
615 *
616 * @param element
617 */
618 public void setup(Element element) {
619 init(element);
620 }
621
622 /**
623 * Initializes the <code>XspfExtensionAnyElement</code> by the Stack <code>stack</code>
624 * that contains Elements.
625 * This constructor is supposed to be used internally
626 * by the Relaxer system.
627 *
628 * @param stack
629 */
630 public void setup(RStack stack) {
631 init(stack.popElement());
632 }
633
634 /**
635 * Initializes the <code>XspfExtensionAnyElement</code> by the File <code>file</code>.
636 *
637 * @param file
638 * @exception IOException
639 * @exception SAXException
640 * @exception ParserConfigurationException
641 */
642 public void setup(File file)
643 throws IOException, SAXException, ParserConfigurationException {
644 setup(file.toURL());
645 }
646
647 /**
648 * Initializes the <code>XspfExtensionAnyElement</code>
649 * by the String representation of URI <code>uri</code>.
650 *
651 * @param uri
652 * @exception IOException
653 * @exception SAXException
654 * @exception ParserConfigurationException
655 */
656 public void setup(String uri)
657 throws IOException, SAXException, ParserConfigurationException {
658 setup(UJAXP.getDocument(uri, UJAXP.FLAG_NONE));
659 }
660
661 /**
662 * Initializes the <code>XspfExtensionAnyElement</code> by the URL <code>url</code>.
663 *
664 * @param url
665 * @exception IOException
666 * @exception SAXException
667 * @exception ParserConfigurationException
668 */
669 public void setup(URL url)
670 throws IOException, SAXException, ParserConfigurationException {
671 setup(UJAXP.getDocument(url, UJAXP.FLAG_NONE));
672 }
673
674 /**
675 * Initializes the <code>XspfExtensionAnyElement</code> by the InputStream <code>in</code>.
676 *
677 * @param in
678 * @exception IOException
679 * @exception SAXException
680 * @exception ParserConfigurationException
681 */
682 public void setup(InputStream in)
683 throws IOException, SAXException, ParserConfigurationException {
684 setup(UJAXP.getDocument(in, UJAXP.FLAG_NONE));
685 }
686
687 /**
688 * Initializes the <code>XspfExtensionAnyElement</code> by the InputSource <code>is</code>.
689 *
690 * @param is
691 * @exception IOException
692 * @exception SAXException
693 * @exception ParserConfigurationException
694 */
695 public void setup(InputSource is)
696 throws IOException, SAXException, ParserConfigurationException {
697 setup(UJAXP.getDocument(is, UJAXP.FLAG_NONE));
698 }
699
700 /**
701 * Initializes the <code>XspfExtensionAnyElement</code> by the Reader <code>reader</code>.
702 *
703 * @param reader
704 * @exception IOException
705 * @exception SAXException
706 * @exception ParserConfigurationException
707 */
708 public void setup(Reader reader)
709 throws IOException, SAXException, ParserConfigurationException {
710 setup(UJAXP.getDocument(reader, UJAXP.FLAG_NONE));
711 }
712
713 /**
714 * Gets number of the IXspfAnythingMixed property <b>content</b>.
715 *
716 * @return int
717 */
718 public int sizeContent() {
719 return (content_.size());
720 }
721
722 /**
723 * Returns a String representation of this object.
724 * While this method informs as XML format representaion,
725 * it's purpose is just information, not making
726 * a rigid XML documentation.
727 *
728 * @return String
729 */
730 public String toString() {
731 try {
732 return (makeTextDocument());
733 } catch (Exception e) {
734 return (super.toString());
735 }
736 }
737
738 /**
739 * @param element
740 */
741 private void init(Element element) {
742 RStack stack = new RStack(element);
743 $localName$ = element.getTagName();
744 this.content_.clear();
745 while (true) {
746 if (RString.isMatch(stack)) {
747 addContent(new RString(stack));
748 } else if (XspfAnythingAnyAttr.isMatch(stack)) {
749 addContent(new XspfAnythingAnyAttr(stack));
750 } else if (XspfAnythingAnyElement.isMatch(stack)) {
751 addContent(new XspfAnythingAnyElement(stack));
752 } else {
753 break;
754 }
755 }
756 }
757 }