protected boolean validateEntities(final ContentSpec contentSpec) {
        final String entities = contentSpec.getEntities();
        if (isNullOrEmpty(entities)) return true;

        boolean valid = true;

        // Make sure the input is valid XML.
        final String wrappedEntities = "<!DOCTYPE section [" + entities + "]><section></section>";
        Document doc = null;
        try {
            doc = XMLUtilities.convertStringToDocument(wrappedEntities);
        } catch (Exception e) {
            final String line = CommonConstants.CS_ENTITIES_TITLE + " = [" + entities + "]";
            log.error(String.format(ProcessorConstants.ERROR_INVALID_ENTITIES_MSG, e.getMessage(), line));
            valid = false;
        }

        // Check that no reserved entities are defined.
        if (doc != null) {
            final List<String> invalidEntities = new ArrayList<String>();
            final NamedNodeMap entityNodes = doc.getDoctype().getEntities();
            for (int i = 0; i < entityNodes.getLength(); i++) {
                final org.w3c.dom.Node entityNode = entityNodes.item(i);
                if (ProcessorConstants.RESERVED_ENTITIES.contains(entityNode.getNodeName())) {
                    invalidEntities.add(entityNode.getNodeName());
                }
            }

            if (!invalidEntities.isEmpty()) {
                final StringBuilder builder = new StringBuilder();
                for (int i = 0; i < invalidEntities.size(); i++) {
                    if (i != 0) {
                        if (i == invalidEntities.size() - 1) {
                            builder.append(" and ");
                        } else {
                            builder.append(", ");
                        }
                    }
                    builder.append(invalidEntities.get(i));
                }

                final String line = CommonConstants.CS_ENTITIES_TITLE + " = [" + entities + "]";
                if (invalidEntities.size() == 1) {
                    log.error(String.format(ProcessorConstants.ERROR_RESERVED_ENTITIES_SINGLE_DEFINED_MSG, builder.toString(), line));
                } else {
                    log.error(String.format(ProcessorConstants.ERROR_RESERVED_ENTITIES_DEFINED_MSG, builder.toString(), line));
                }
                valid = false;
            }
        }

        return valid;
    }
protected boolean validateEntities ( final ContentSpec contentSpec ) { final String entities = contentSpec . getEntities ( ) ; if ( isNullOrEmpty ( entities ) ) return true ; boolean valid = true ; final String wrappedEntities = "<!DOCTYPE section [" + entities + "]><section></section>" ; Document doc = null ; try { doc = XMLUtilities . convertStringToDocument ( wrappedEntities ) ; } catch ( Exception e ) { final String line = CommonConstants . CS_ENTITIES_TITLE + " = [" + entities + "]" ; log . error ( String . format ( ProcessorConstants . ERROR_INVALID_ENTITIES_MSG , e . getMessage ( ) , line ) ) ; valid = false ; } if ( doc != null ) { final List < String > invalidEntities = new ArrayList < String > ( ) ; final NamedNodeMap entityNodes = doc . getDoctype ( ) . getEntities ( ) ; for ( int i = 0 ; i < entityNodes . getLength ( ) ; i ++ ) { final org . w3c . dom . Node entityNode = entityNodes . item ( i ) ; if ( ProcessorConstants . RESERVED_ENTITIES . contains ( entityNode . getNodeName ( ) ) ) { invalidEntities . add ( entityNode . getNodeName ( ) ) ; } } if ( ! invalidEntities . isEmpty ( ) ) { final StringBuilder builder = new StringBuilder ( ) ; for ( int i = 0 ; i < invalidEntities . size ( ) ; i ++ ) { if ( i != 0 ) { if ( i == invalidEntities . size ( ) - 1 ) { builder . append ( " and " ) ; } else { builder . append ( ", " ) ; } } builder . append ( invalidEntities . get ( i ) ) ; } final String line = CommonConstants . CS_ENTITIES_TITLE + " = [" + entities + "]" ; if ( invalidEntities . size ( ) == 1 ) { log . error ( String . format ( ProcessorConstants . ERROR_RESERVED_ENTITIES_SINGLE_DEFINED_MSG , builder . toString ( ) , line ) ) ; } else { log . error ( String . format ( ProcessorConstants . ERROR_RESERVED_ENTITIES_DEFINED_MSG , builder . toString ( ) , line ) ) ; } valid = false ; } } return valid ; }
Validates the custom entities to ensure that only the defaults are overridden and that the content is valid XML.

@param contentSpec The content spec that contains the custom entities to be validated.
@return True if the custom entities are valid and don't contain additional custom values, otherwise false.