nickdavis 01/04/11 13:43:22
Modified: src/antidote/org/apache/tools/ant/gui/acs
ACSDtdDefinedElement.java ACSDocumentType.java
Log:
add support for optional elements
Revision Changes Path
1.4 +27 -9
jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs/ACSDtdDefinedElement.java
Index: ACSDtdDefinedElement.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs/ACSDtdDefinedElement.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ACSDtdDefinedElement.java 2001/04/06 18:40:03 1.3
+++ ACSDtdDefinedElement.java 2001/04/11 20:43:21 1.4
@@ -53,6 +53,7 @@
*/
package org.apache.tools.ant.gui.acs;
import org.apache.tools.ant.gui.command.NewElementCmd;
+import org.apache.tools.ant.gui.util.Collections;
import org.w3c.dom.*;
import java.beans.*;
import java.util.*;
@@ -60,7 +61,7 @@
/**
* Element defined by the DTD.
*
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
* @author Nick Davis<a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>
*/
public class ACSDtdDefinedElement extends ACSTreeNodeElement
@@ -181,12 +182,21 @@
}
ACSDocumentType.DtdElement e =
- docType.findElement(name);
+ docType.findElement(ACSDocumentType.CORE_ELEMENT, name);
+ if (e == null) {
+ e = docType.findElement(ACSDocumentType.OPTIONAL_ELEMENT, name);
+ }
if (e != null) {
// Use the content model (all the possible
// sub-elements) to create the menu.
String[] temp = e.getContentModel();
+
+ // Sort the items
+ List list = Collections.fill(null, temp);
+ java.util.Collections.sort(list);
+ list.toArray(temp);
+
int size = (temp.length > 5) ? 5 : temp.length;
// The project doesn't need a delete menu
@@ -222,15 +232,17 @@
}
/**
- * Retuns a string array which contains this elements
- * possible children. It is created from the DTD's
- * content model.
+ * Returns a string array which contains this elements
+ * possible children.
+ *
+ * @param childType ACSDocumentType.CORE_ELEMENT or
+ * ACSDocumentType.OPTIONAL_ELEMENT
*/
- public String[] getPossibleChildren() {
+ public String[] getPossibleChildren(int childType) {
String name = getTagName();
+
ACSDocumentType.DtdElement e =
- docType.findElement(name);
-
+ docType.findElement(childType, name);
if (e != null) {
return e.getContentModel();
}
@@ -266,7 +278,13 @@
}
String name = getNodeName();
- _dtdElement = docType.findElement(name);
+
+ _dtdElement = docType.findElement(ACSDocumentType.CORE_ELEMENT,
name);
+ if (_dtdElement == null) {
+ _dtdElement = docType.findElement(
+ ACSDocumentType.OPTIONAL_ELEMENT, name);
+ }
+
return _dtdElement;
}
}
1.3 +57 -21
jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs/ACSDocumentType.java
Index: ACSDocumentType.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/antidote/org/apache/tools/ant/gui/acs/ACSDocumentType.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ACSDocumentType.java 2001/04/06 15:45:34 1.2
+++ ACSDocumentType.java 2001/04/11 20:43:21 1.3
@@ -68,20 +68,36 @@
/**
* Reads the ANT DTD and provides information about it.
*
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
* @author Nick Davis<a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>
*/
public class ACSDocumentType extends java.lang.Object {
+ /** ID for core elements */
+ public final static int CORE_ELEMENT = 0;
+ /** ID for optional elements */
+ public final static int OPTIONAL_ELEMENT = 1;
/** True if the DTD has been loaded */
private boolean isInit = false;
+ /** Hold the core DTD elements */
+ private HashMap coreElementMap = new HashMap();
+ /** Hold the optional DTD elements */
+ private HashMap optionalElementMap = new HashMap();
/** Hold the DTD elements */
- private HashMap elementMap = new HashMap();
- /** XML document used to load the DTD */
- final static String XMLDOC =
+ private HashMap elementMap;
+ /** First part of the XML document used to load the DTD */
+ private final static String XMLDOC_1 =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
- "<!DOCTYPE project SYSTEM \"file:/project.dtd\">" +
- "<project name=\"sample-project\">" +
+ "<!DOCTYPE project SYSTEM \"file:/";
+ /** Second part of the XML document used to load the DTD */
+ private final static String XMLDOC_2 =
+ "\"><project name=\"sample-project\">" +
"</project>";
+ /** DTD which holds the core tasks */
+ private final static String DTD_1 = "project.dtd";
+ /** DTD which holds the optional tasks */
+ private final static String DTD_2 = "project-ext.dtd";
+ /** DTD which holds the shared elements */
+ private final static String DTD_SHARE = "share.dtd";
/**
* Standard ctor.
@@ -114,13 +130,21 @@
DtdHandler dtdh = new DtdHandler();
p.setDTDHandler(dtdh);
- // Create the default xml file
- InputSource xmldoc = new InputSource(
- new ByteArrayInputStream(XMLDOC.getBytes()));
+ String coreDoc = XMLDOC_1 + DTD_1 + XMLDOC_2;
+ String optionalDoc = XMLDOC_1 + DTD_2 + XMLDOC_2;
- // Parse the document
- p.parse(xmldoc);
+ // Parse the core task DTD
+ elementMap = coreElementMap;
+ InputSource xmldocCore = new InputSource(
+ new ByteArrayInputStream(coreDoc.getBytes()));
+ p.parse(xmldocCore);
+ // Parse the core task DTD
+ elementMap = optionalElementMap;
+ InputSource xmldocOptional = new InputSource(
+ new ByteArrayInputStream(optionalDoc.getBytes()));
+ p.parse(xmldocOptional);
+
isInit = true;
} catch (Exception e) {
System.out.println(e);
@@ -130,10 +154,14 @@
/**
* Returns the dtd element.
*
+ * @param elementType CORE_ELEMENT or OPTIONAL_ELEMENT
* @param name the element name
*/
- public DtdElement findElement(String name) {
- return (DtdElement) elementMap.get(name);
+ public DtdElement findElement(int elementType, String name) {
+ if (elementType == OPTIONAL_ELEMENT) {
+ return (DtdElement) optionalElementMap.get(name);
+ }
+ return (DtdElement) coreElementMap.get(name);
}
/**
@@ -247,7 +275,7 @@
Iterator i = values().iterator();
while(i.hasNext()) {
DtdAttribute a = (DtdAttribute)i.next();
- if (a.isRequired()) {
+ if (!a.isRequired()) {
list.add(a.getName());
}
}
@@ -264,7 +292,7 @@
Iterator i = values().iterator();
while(i.hasNext()) {
DtdAttribute a = (DtdAttribute)i.next();
- if (!a.isRequired()) {
+ if (a.isRequired()) {
list.add(a.getName());
}
}
@@ -438,22 +466,30 @@
String systemId)
throws SAXException, IOException {
- final String PROJECT = "project.dtd";
- final String PROJECTEXT = "project-ext.dtd";
InputStream result = null;
// Is it the project.dtd?
- if (systemId.indexOf(PROJECT) != -1) {
+ if (systemId.indexOf(DTD_1) != -1) {
try {
// Look for it as a resource
- result = getClass().getResourceAsStream(PROJECT);
+ result = getClass().getResourceAsStream(DTD_1);
} catch (Exception e) {}
}
// Is it the project-ext.dtd?
- if (systemId.indexOf(PROJECTEXT) != -1) {
+ if (systemId.indexOf(DTD_2) != -1) {
+ try {
+ // Look for it as a resource
+ result = getClass().getResourceAsStream(DTD_2);
+ } catch (Exception e) {}
+ }
+ if (result != null) {
+ return new InputSource(result);
+ }
+ // Is it the share.dtd?
+ if (systemId.indexOf(DTD_SHARE) != -1) {
try {
// Look for it as a resource
- result = getClass().getResourceAsStream(PROJECTEXT);
+ result = getClass().getResourceAsStream(DTD_SHARE);
} catch (Exception e) {}
}
if (result != null) {