KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > zeus > util > DTDUtils


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  */

19 package org.enhydra.zeus.util;
20
21 import java.util.Hashtable;
22 import java.util.Enumeration;
23
24 // DTD Parser
25
import com.wutka.dtd.DTDElement;
26 import com.wutka.dtd.DTDMixed;
27 import com.wutka.dtd.DTDPCData;
28
29 /**
30  * <p>
31  * <code>DTDUtils</code> provides utility methods specific to DTDs
32  * and code dealing with DTDs.
33  * </p>
34  *
35  * @author Brett McLaughlin
36  * @author Maciej Zawadzki
37  */

38 public class DTDUtils {
39
40     /**
41      * <p>
42      * Helper method to determine whether the specified element is simple.
43      * </p>
44      *
45      * @param element the <code>{@link DTDElement}</code> to examine.
46      * @param ignoreIDAttributes whether or not to ignore ID attributes
47      * on the supplied element.
48      */

49     public static boolean isSimpleElement(DTDElement element,
50                                           boolean ignoreIDAttributes) {
51         if (element == null) {
52             throw new IllegalArgumentException("A non-null DTDElement must " +
53                 "be supplied to DTDUtils methods.");
54         }
55         
56         boolean result = true;
57
58         if ((element.getContent() instanceof DTDPCData) ||
59             (element.getContent() instanceof DTDMixed)) {
60
61             // get attributes
62
Hashtable attributes = element.attributes;
63             String key = null;
64             // if there are no attributes, than it is simple
65
for (Enumeration enum = attributes.keys();
66                  enum.hasMoreElements(); ) {
67                 key = (String)enum.nextElement();
68                 
69                 /**
70                  * Skip attributes whose name starts with "dt_" for now
71                  * We'll map them to Java types later
72                  */

73                 if (!key.startsWith("dt_")) {
74                     // If ignoring ID attributes, skip them
75
if (ignoreIDAttributes) {
76                         if (key.equalsIgnoreCase("id")) {
77                             continue;
78                         }
79                     }
80                     result = false;
81                     break;
82                 }
83             }
84         } else {
85             result = false;
86         }
87         return result;
88     }
89 }
90
Popular Tags