protected void validateInput()

in eclipse/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/actions/NewNodeDialog.java [174:234]


    protected void validateInput() {
        final String firstInput = getText().getText();
        final String secondInput = comboSelection;
        try {
            if (secondInput==null || secondInput.length()==0) {
                setErrorMessage("");
            } else if (ntManager==null) {
                setErrorMessage(null);
            } else if (ntManager.isAllowedPrimaryChildNodeType(parentNodeType, secondInput)) {
                // also check on the name, not only the type
                if (allChildNodeDefs==null) {
                    setErrorMessage("No child node definitions found for "+parentNodeType);
                } else {
                    boolean success = false;
                    for (int i = 0; i < allChildNodeDefs.length; i++) {
                        NodeDefinition aChildNodeDef = allChildNodeDefs[i];
                        if (aChildNodeDef.getName()!=null && aChildNodeDef.getName().length()>0) {
                            if (firstInput.equals(aChildNodeDef.getName())) {
                                setErrorMessage(null);
                                return;
                            }
                        } else {
                            // mark success if there's a child node definition without a name
                            // (ie then it can be any name)
                            success = true;
                        }
                    }
                    if (success) {
                        setErrorMessage(null);
                        return;
                    }
                    StringBuffer details = new StringBuffer();
                    for (NodeDefinition aChildNodeDef : allChildNodeDefs) {
                        if (details.length()!=0) {
                            details.append(", ");
                        }
                        details.append("(name="+aChildNodeDef.getName()+", required primary type(s)=");
                        String[] requiredPrimaryTypeNames = aChildNodeDef.getRequiredPrimaryTypeNames();
                        if (requiredPrimaryTypeNames==null) {
                            details.append("null");
                        } else {
                            for (int j = 0; j < requiredPrimaryTypeNames.length; j++) {
                                String rptn = requiredPrimaryTypeNames[j];
                                if (j>0) {
                                    details.append(",");
                                }
                                details.append(rptn);
                            }
                        }
                        details.append(")");
                    }
                    setErrorMessage("No matching child node definition found for "+parentNodeType+". Expected one of: "+details);
                }
            } else {
                setErrorMessage("Error: Invalid child node type of "+parentNodeType);
            }
        } catch(RepositoryException e) {
            setErrorMessage("RepositoryException: "+e);
        }
        
    };