*/
private List getAvailableRootChildren(Document document, int childIndex) {
List list = null;
// extract the valid 'root' node name from the DocumentType Node
DocumentType docType = document.getDoctype();
String rootName = null;
if (docType != null) {
rootName = docType.getNodeName();
}
if (rootName == null) {
return new ArrayList(0);
}
for (Node child = document.getFirstChild(); child != null; child = child.getNextSibling()) {
// make sure the "root" Element isn't already present
// is it required to be an Element?
if ((child.getNodeType() == Node.ELEMENT_NODE) && child.getNodeName().equalsIgnoreCase(rootName)) {
// if the node is missing either the start or end tag, don't
// count it as present
if ((child instanceof IDOMNode) && ((((IDOMNode) child).getStartStructuredDocumentRegion() == null) || (((IDOMNode) child).getEndStructuredDocumentRegion() == null))) {
continue;
}
if (Debug.displayInfo) {
System.out.println(rootName + " already present!"); //$NON-NLS-1$
}
setErrorMessage(NLS.bind(XMLUIMessages.The_document_element__, (new Object[]{rootName})));
return new ArrayList(0);
}
}
list = new ArrayList(1);
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
if (modelQuery != null) {
CMDocument cmdoc = modelQuery.getCorrespondingCMDocument(document);
if (cmdoc != null) {
if (rootName != null) {
CMElementDeclaration rootDecl = (CMElementDeclaration) cmdoc.getElements().getNamedItem(rootName);
if (rootDecl != null) {
list.add(rootDecl);
}
else {
// supply the given document name anyway, even if it
// is an error
list.add(new SimpleCMElementDeclaration(rootName));
String location = "" + (docType.getPublicId() != null ? docType.getPublicId() + "/" : "") + (docType.getSystemId() != null ? docType.getSystemId() : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
if (location.length() > 0) {
setErrorMessage(NLS.bind(
XMLUIMessages.No_definition_for_in,
(new Object[]{rootName, location})));
}
else {
setErrorMessage(NLS.bind(
XMLUIMessages.No_definition_for,
(new Object[]{rootName})));
}
}
}
}
else {
String location = "" + (docType.getPublicId() != null ? docType.getPublicId() + "/" : "") + (docType.getSystemId() != null ? docType.getSystemId() : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
if (location.length() > 0) {
setErrorMessage(NLS.bind(
XMLUIMessages.No_content_model_for,
(new Object[]{location})));
}