com.sun.org.apache.xerces.internal.util.XMLChar Java Examples

The following examples show how to use com.sun.org.apache.xerces.internal.util.XMLChar. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IDREFDatatypeValidator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks that "content" string is valid IDREF value.
 * If invalid a Datatype validation exception is thrown.
 *
 * @param content       the string value that needs to be validated
 * @param context       the validation context
 * @throws InvalidDatatypeException if the content is
 *         invalid according to the rules for the validators
 * @see InvalidDatatypeValueException
 */
public void validate(String content, ValidationContext context) throws InvalidDatatypeValueException {

    //Check if is valid key-[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
    if(context.useNamespaces()) {
        if (!XMLChar.isValidNCName(content)) {
            throw new InvalidDatatypeValueException("IDREFInvalidWithNamespaces", new Object[]{content});
        }
    }
    else {
        if (!XMLChar.isValidName(content)) {
            throw new InvalidDatatypeValueException("IDREFInvalid", new Object[]{content});
        }
    }

    context.addIdRef(content);

}
 
Example #2
Source File: IDREFDatatypeValidator.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Checks that "content" string is valid IDREF value.
 * If invalid a Datatype validation exception is thrown.
 *
 * @param content       the string value that needs to be validated
 * @param context       the validation context
 * @throws InvalidDatatypeException if the content is
 *         invalid according to the rules for the validators
 * @see InvalidDatatypeValueException
 */
public void validate(String content, ValidationContext context) throws InvalidDatatypeValueException {

    //Check if is valid key-[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
    if(context.useNamespaces()) {
        if (!XMLChar.isValidNCName(content)) {
            throw new InvalidDatatypeValueException("IDREFInvalidWithNamespaces", new Object[]{content});
        }
    }
    else {
        if (!XMLChar.isValidName(content)) {
            throw new InvalidDatatypeValueException("IDREFInvalid", new Object[]{content});
        }
    }

    context.addIdRef(content);

}
 
Example #3
Source File: IDDatatypeValidator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks that "content" string is valid ID value.
 * If invalid a Datatype validation exception is thrown.
 *
 * @param content       the string value that needs to be validated
 * @param context       the validation context
 * @throws InvalidDatatypeException if the content is
 *         invalid according to the rules for the validators
 * @see InvalidDatatypeValueException
 */
public void validate(String content, ValidationContext context) throws InvalidDatatypeValueException {

    //Check if is valid key-[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
    if(context.useNamespaces()) {
        if (!XMLChar.isValidNCName(content)) {
            throw new InvalidDatatypeValueException("IDInvalidWithNamespaces", new Object[]{content});
        }
    }
    else {
        if (!XMLChar.isValidName(content)) {
            throw new InvalidDatatypeValueException("IDInvalid", new Object[]{content});
        }
    }

    if (context.isIdDeclared(content)) {
        throw new InvalidDatatypeValueException("IDNotUnique", new Object[]{content});
    }

    context.addId(content);
}
 
Example #4
Source File: IDDatatypeValidator.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks that "content" string is valid ID value.
 * If invalid a Datatype validation exception is thrown.
 *
 * @param content       the string value that needs to be validated
 * @param context       the validation context
 * @throws InvalidDatatypeException if the content is
 *         invalid according to the rules for the validators
 * @see InvalidDatatypeValueException
 */
public void validate(String content, ValidationContext context) throws InvalidDatatypeValueException {

    //Check if is valid key-[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
    if(context.useNamespaces()) {
        if (!XMLChar.isValidNCName(content)) {
            throw new InvalidDatatypeValueException("IDInvalidWithNamespaces", new Object[]{content});
        }
    }
    else {
        if (!XMLChar.isValidName(content)) {
            throw new InvalidDatatypeValueException("IDInvalid", new Object[]{content});
        }
    }

    if (context.isIdDeclared(content)) {
        throw new InvalidDatatypeValueException("IDNotUnique", new Object[]{content});
    }

    context.addId(content);
}
 
Example #5
Source File: IDDatatypeValidator.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks that "content" string is valid ID value.
 * If invalid a Datatype validation exception is thrown.
 *
 * @param content       the string value that needs to be validated
 * @param context       the validation context
 * @throws InvalidDatatypeException if the content is
 *         invalid according to the rules for the validators
 * @see InvalidDatatypeValueException
 */
public void validate(String content, ValidationContext context) throws InvalidDatatypeValueException {

    //Check if is valid key-[81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
    if(context.useNamespaces()) {
        if (!XMLChar.isValidNCName(content)) {
            throw new InvalidDatatypeValueException("IDInvalidWithNamespaces", new Object[]{content});
        }
    }
    else {
        if (!XMLChar.isValidName(content)) {
            throw new InvalidDatatypeValueException("IDInvalid", new Object[]{content});
        }
    }

    if (context.isIdDeclared(content)) {
        throw new InvalidDatatypeValueException("IDNotUnique", new Object[]{content});
    }

    context.addId(content);
}
 
Example #6
Source File: XMLScanner.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Scans surrogates and append them to the specified buffer.
 * <p>
 * <strong>Note:</strong> This assumes the current char has already been
 * identified as a high surrogate.
 *
 * @param buf The StringBuffer to append the read surrogates to.
 * @return True if it succeeded.
 */
protected boolean scanSurrogates(XMLStringBuffer buf)
throws IOException, XNIException {

    int high = fEntityScanner.scanChar(null);
    int low = fEntityScanner.peekChar();
    if (!XMLChar.isLowSurrogate(low)) {
        reportFatalError("InvalidCharInContent",
                new Object[] {Integer.toString(high, 16)});
                return false;
    }
    fEntityScanner.scanChar(null);

    // convert surrogates to supplemental character
    int c = XMLChar.supplemental((char)high, (char)low);

    // supplemental character must be a valid XML character
    if (isInvalid(c)) {
        reportFatalError("InvalidCharInContent",
                new Object[]{Integer.toString(c, 16)});
                return false;
    }

    // fill in the buffer
    buf.append((char)high);
    buf.append((char)low);

    return true;

}
 
Example #7
Source File: XMLSchemaValidator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public boolean characterData(String data, Augmentations augs) {

        fSawText = fSawText || data.length() > 0;

        // REVISIT: this methods basically duplicates implementation of
        //          handleCharacters(). We should be able to reuse some code

        // if whitespace == -1 skip normalization, because it is a complexType
        // or a union type.
        if (fNormalizeData && fWhiteSpace != -1 && fWhiteSpace != XSSimpleType.WS_PRESERVE) {
            // normalize data
            normalizeWhitespace(data, fWhiteSpace == XSSimpleType.WS_COLLAPSE);
            fBuffer.append(fNormalizedStr.ch, fNormalizedStr.offset, fNormalizedStr.length);
        } else {
            if (fAppendBuffer)
                fBuffer.append(data);
        }

        // When it's a complex type with element-only content, we need to
        // find out whether the content contains any non-whitespace character.
        boolean allWhiteSpace = true;
        if (fCurrentType != null
            && fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
            XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType;
            if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT) {
                // data outside of element content
                for (int i = 0; i < data.length(); i++) {
                    if (!XMLChar.isSpace(data.charAt(i))) {
                        allWhiteSpace = false;
                        fSawCharacters = true;
                        break;
                    }
                }
            }
        }

        return allWhiteSpace;
    }
 
Example #8
Source File: XML11DTDScannerImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Checks whether this string would be unchanged by normalization.
 *
 * @return -1 if the value would be unchanged by normalization,
 * otherwise the index of the first whitespace character which
 * would be transformed.
 */
protected int isUnchangedByNormalization(XMLString value) {
    int end = value.offset + value.length;
    for (int i = value.offset; i < end; ++i) {
        int c = value.ch[i];
        if (XMLChar.isSpace(c)) {
            return i - value.offset;
        }
    }
    return -1;
}
 
Example #9
Source File: XMLSchemaValidator.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
XMLString handleCharacters(XMLString text) {

        if (fSkipValidationDepth >= 0)
            return text;

        fSawText = fSawText || text.length > 0;

        // Note: data in EntityRef and CDATA is normalized as well
        // if whitespace == -1 skip normalization, because it is a complexType
        // or a union type.
        if (fNormalizeData && fWhiteSpace != -1 && fWhiteSpace != XSSimpleType.WS_PRESERVE) {
            // normalize data
            normalizeWhitespace(text, fWhiteSpace == XSSimpleType.WS_COLLAPSE);
            text = fNormalizedStr;
        }
        if (fAppendBuffer)
            fBuffer.append(text.ch, text.offset, text.length);

        // When it's a complex type with element-only content, we need to
        // find out whether the content contains any non-whitespace character.
        fSawOnlyWhitespaceInElementContent = false;
        if (fCurrentType != null
            && fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
            XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType;
            if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT) {
                // data outside of element content
                for (int i = text.offset; i < text.offset + text.length; i++) {
                    if (!XMLChar.isSpace(text.ch[i])) {
                        fSawCharacters = true;
                        break;
                    }
                    fSawOnlyWhitespaceInElementContent = !fSawCharacters;
                }
            }
        }

        return text;
    }
 
Example #10
Source File: CoreDocumentImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks if the given qualified name is legal with respect
 * to the version of XML to which this document must conform.
 *
 * @param prefix prefix of qualified name
 * @param local local part of qualified name
 */
protected final void checkQName(String prefix, String local) {
    if (!errorChecking) {
        return;
    }

    // check that both prefix and local part match NCName
    boolean validNCName = false;
    if (!xml11Version) {
        validNCName = (prefix == null || XMLChar.isValidNCName(prefix))
                && XMLChar.isValidNCName(local);
    }
    else {
        validNCName = (prefix == null || XML11Char.isXML11ValidNCName(prefix))
                && XML11Char.isXML11ValidNCName(local);
    }

    if (!validNCName) {
        // REVISIT: add qname parameter to the message
        String msg =
        DOMMessageFormatter.formatMessage(
                        DOMMessageFormatter.DOM_DOMAIN,
                        "INVALID_CHARACTER_ERR",
                        null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
}
 
Example #11
Source File: XMLDocumentFragmentScannerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
boolean skipQElement(String rawname) throws IOException{

        final int c = fEntityScanner.getChar(rawname.length());
        //if this character is still valid element name -- this means string can't match
        if(XMLChar.isName(c)){
            return false;
        }else{
            return fEntityScanner.skipString(rawname);
        }
    }
 
Example #12
Source File: XMLScanner.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Scans a comment.
 * <p>
 * <pre>
 * [15] Comment ::= '&lt!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
 * </pre>
 * <p>
 * <strong>Note:</strong> Called after scanning past '&lt;!--'
 * <strong>Note:</strong> This method uses fString, anything in it
 * at the time of calling is lost.
 *
 * @param text The buffer to fill in with the text.
 */
protected void scanComment(XMLStringBuffer text)
throws IOException, XNIException {

    //System.out.println( "XMLScanner#scanComment# In Scan Comment" );
    // text
    // REVISIT: handle invalid character, eof
    text.clear();
    while (fEntityScanner.scanData("--", text, 0)) {
        int c = fEntityScanner.peekChar();

        //System.out.println( "XMLScanner#scanComment#text.toString() == " + text.toString() );
        //System.out.println( "XMLScanner#scanComment#c == " + c );

        if (c != -1) {
            if (XMLChar.isHighSurrogate(c)) {
                scanSurrogates(text);
            }
            else if (isInvalidLiteral(c)) {
                reportFatalError("InvalidCharInComment",
                        new Object[] { Integer.toHexString(c) });
                        fEntityScanner.scanChar(NameType.COMMENT);
            }
        }
    }
    if (!fEntityScanner.skipChar('>', NameType.COMMENT)) {
        reportFatalError("DashDashInComment", null);
    }

}
 
Example #13
Source File: XML11DTDScannerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Normalize whitespace in an XMLString converting all whitespace
 * characters to space characters.
 */
protected void normalizeWhitespace(XMLString value, int fromIndex) {
    int end = value.offset + value.length;
    for (int i = value.offset + fromIndex; i < end; ++i) {
        int c = value.ch[i];
        if (XMLChar.isSpace(c)) {
            value.ch[i] = ' ';
        }
    }
}
 
Example #14
Source File: CoreDocumentImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check the string against XML's definition of acceptable names for
 * elements and attributes and so on using the XMLCharacterProperties
 * utility class
 */

public static final boolean isXMLName(String s, boolean xml11Version) {

    if (s == null) {
        return false;
    }
    if(!xml11Version)
        return XMLChar.isValidName(s);
    else
        return XML11Char.isXML11ValidName(s);

}
 
Example #15
Source File: XML11DocumentScannerImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Normalize whitespace in an XMLString converting all whitespace
 * characters to space characters.
 */
protected void normalizeWhitespace(XMLString value, int fromIndex) {
    int end = value.offset + value.length;
    for (int i = value.offset + fromIndex; i < end; ++i) {
        int c = value.ch[i];
        if (XMLChar.isSpace(c)) {
            value.ch[i] = ' ';
        }
    }
}
 
Example #16
Source File: BaseMarkupSerializer.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected void surrogates(int high, int low) throws IOException{
    if (XMLChar.isHighSurrogate(high)) {
        if (!XMLChar.isLowSurrogate(low)) {
            //Invalid XML
            fatalError("The character '"+(char)low+"' is an invalid XML character");
        }
        else {
            int supplemental = XMLChar.supplemental((char)high, (char)low);
            if (!XMLChar.isValid(supplemental)) {
                //Invalid XML
                fatalError("The character '"+(char)supplemental+"' is an invalid XML character");
            }
            else {
                if (content().inCData ) {
                    _printer.printText("]]>&#x");
                    _printer.printText(Integer.toHexString(supplemental));
                    _printer.printText(";<![CDATA[");
                }
                else {
                    printHex(supplemental);
                }
            }
        }
    } else {
        fatalError("The character '"+(char)high+"' is an invalid XML character");
    }

}
 
Example #17
Source File: XMLSchemaValidator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void normalizeWhitespace(String value, boolean collapse) {
    boolean skipSpace = collapse;
    char c;
    int size = value.length();

    // ensure the ch array is big enough
    if (fNormalizedStr.ch == null || fNormalizedStr.ch.length < size) {
        fNormalizedStr.ch = new char[size];
    }
    fNormalizedStr.offset = 0;
    fNormalizedStr.length = 0;

    for (int i = 0; i < size; i++) {
        c = value.charAt(i);
        if (XMLChar.isSpace(c)) {
            if (!skipSpace) {
                // take the first whitespace as a space and skip the others
                fNormalizedStr.ch[fNormalizedStr.length++] = ' ';
                skipSpace = collapse;
            }
        } else {
            fNormalizedStr.ch[fNormalizedStr.length++] = c;
            skipSpace = false;
        }
    }
    if (skipSpace) {
        if (fNormalizedStr.length != 0)
            // if we finished on a space trim it but also record it
            fNormalizedStr.length--;
    }
}
 
Example #18
Source File: QNameDV.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public Object getActualValue(String content, ValidationContext context)
    throws InvalidDatatypeValueException {

    // "prefix:localpart" or "localpart"
    // get prefix and local part out of content
    String prefix, localpart;
    int colonptr = content.indexOf(":");
    if (colonptr > 0) {
        prefix = context.getSymbol(content.substring(0,colonptr));
        localpart = content.substring(colonptr+1);
    } else {
        prefix = EMPTY_STRING;
        localpart = content;
    }

    // both prefix (if any) a nd localpart must be valid NCName
    if (prefix.length() > 0 && !XMLChar.isValidNCName(prefix))
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "QName"});

    if(!XMLChar.isValidNCName(localpart))
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "QName"});

    // resove prefix to a uri, report an error if failed
    String uri = context.getURI(prefix);
    if (prefix.length() > 0 && uri == null)
        throw new InvalidDatatypeValueException("UndeclaredPrefix", new Object[]{content, prefix});

    return new XQName(prefix, context.getSymbol(localpart), context.getSymbol(content), uri);

}
 
Example #19
Source File: CoreDocumentImpl.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the given qualified name is legal with respect
 * to the version of XML to which this document must conform.
 *
 * @param prefix prefix of qualified name
 * @param local local part of qualified name
 */
protected final void checkQName(String prefix, String local) {
    if (!errorChecking) {
        return;
    }

    // check that both prefix and local part match NCName
    boolean validNCName = false;
    if (!xml11Version) {
        validNCName = (prefix == null || XMLChar.isValidNCName(prefix))
                && XMLChar.isValidNCName(local);
    }
    else {
        validNCName = (prefix == null || XML11Char.isXML11ValidNCName(prefix))
                && XML11Char.isXML11ValidNCName(local);
    }

    if (!validNCName) {
        // REVISIT: add qname parameter to the message
        String msg =
        DOMMessageFormatter.formatMessage(
                        DOMMessageFormatter.DOM_DOMAIN,
                        "INVALID_CHARACTER_ERR",
                        null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
}
 
Example #20
Source File: DTDGrammarUtil.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public boolean isIgnorableWhiteSpace(XMLString text) {
    if (isInElementContent()) {
        for (int i = text.offset; i < text.offset + text.length; i++) {
            if (!XMLChar.isSpace(text.ch[i])) {
                return false;
            }
        }
        return true;
    }
    return false;
}
 
Example #21
Source File: XML11Serializer.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
protected final void surrogates(int high, int low) throws IOException{
    if (XMLChar.isHighSurrogate(high)) {
        if (!XMLChar.isLowSurrogate(low)) {
            //Invalid XML
            fatalError("The character '"+(char)low+"' is an invalid XML character");
        }
        else {
            int supplemental = XMLChar.supplemental((char)high, (char)low);
            if (!XML11Char.isXML11Valid(supplemental)) {
                //Invalid XML
                fatalError("The character '"+(char)supplemental+"' is an invalid XML character");
            }
            else {
                if (content().inCData ) {
                    _printer.printText("]]>&#x");
                    _printer.printText(Integer.toHexString(supplemental));
                    _printer.printText(";<![CDATA[");
                }
                else {
                                            printHex(supplemental);
                }
            }
        }
    } else {
        fatalError("The character '"+(char)high+"' is an invalid XML character");
    }

}
 
Example #22
Source File: SchemaDOMParser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Character content.
 *
 * @param text   The content.
 * @param augs   Additional information that may include infoset augmentations
 *
 * @exception XNIException
 *                   Thrown by handler to signal an error.
 */
public void characters(XMLString text, Augmentations augs) throws XNIException {
    // when it's not within xs:appinfo or xs:documentation
    if (fInnerAnnotationDepth == -1 ) {
        for (int i=text.offset; i<text.offset+text.length; i++) {
            // and there is a non-whitespace character
            if (!XMLChar.isSpace(text.ch[i])) {
                // the string we saw: starting from the first non-whitespace character.
                String txt = new String(text.ch, i, text.length+text.offset-i);
                // report an error
                fErrorReporter.reportError(fLocator,
                        XSMessageFormatter.SCHEMA_DOMAIN,
                        "s4s-elt-character",
                        new Object[]{txt},
                        XMLErrorReporter.SEVERITY_ERROR);
                break;
            }
        }
        // don't call super.characters() when it's not within one of the 2
        // annotation elements: the traversers ignore them anyway. We can
        // save time/memory creating the text nodes.
    }
    // when it's within either of the 2 elements, characters are allowed
    // and we need to store them.
    else {
        schemaDOM.characters(text);
    }

}
 
Example #23
Source File: XML11DTDScannerImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks whether this string would be unchanged by normalization.
 *
 * @return -1 if the value would be unchanged by normalization,
 * otherwise the index of the first whitespace character which
 * would be transformed.
 */
protected int isUnchangedByNormalization(XMLString value) {
    int end = value.offset + value.length;
    for (int i = value.offset; i < end; ++i) {
        int c = value.ch[i];
        if (XMLChar.isSpace(c)) {
            return i - value.offset;
        }
    }
    return -1;
}
 
Example #24
Source File: XML11DTDScannerImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks whether this string would be unchanged by normalization.
 *
 * @return -1 if the value would be unchanged by normalization,
 * otherwise the index of the first whitespace character which
 * would be transformed.
 */
protected int isUnchangedByNormalization(XMLString value) {
    int end = value.offset + value.length;
    for (int i = value.offset; i < end; ++i) {
        int c = value.ch[i];
        if (XMLChar.isSpace(c)) {
            return i - value.offset;
        }
    }
    return -1;
}
 
Example #25
Source File: CoreDocumentImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check the string against XML's definition of acceptable names for
 * elements and attributes and so on using the XMLCharacterProperties
 * utility class
 */

public static final boolean isXMLName(String s, boolean xml11Version) {

    if (s == null) {
        return false;
    }
    if(!xml11Version)
        return XMLChar.isValidName(s);
    else
        return XML11Char.isXML11ValidName(s);

}
 
Example #26
Source File: XMLStreamReaderImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  Returns true if the cursor points to a character data event that consists of all whitespace
 *  Application calling this method needs to cache the value and avoid calling this method again
 *  for the same event.
 * @return
 */
public boolean isWhiteSpace() {
    if(isCharacters() || (fEventType == XMLStreamConstants.CDATA)){
        char [] ch = this.getTextCharacters();
        final int start = this.getTextStart();
        final int end = start + this.getTextLength();
        for (int i = start; i < end; i++){
            if(!XMLChar.isSpace(ch[i])){
                return false;
            }
        }
        return true;
    }
    return false;
}
 
Example #27
Source File: XML11DTDScannerImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Normalize whitespace in an XMLString converting all whitespace
 * characters to space characters.
 */
protected void normalizeWhitespace(XMLString value, int fromIndex) {
    int end = value.offset + value.length;
    for (int i = value.offset + fromIndex; i < end; ++i) {
        int c = value.ch[i];
        if (XMLChar.isSpace(c)) {
            value.ch[i] = ' ';
        }
    }
}
 
Example #28
Source File: XIncludeHandler.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks whether the string only contains white space characters.
 *
 * @param value the text to check
 */
private void checkWhitespace(XMLString value) {
    int end = value.offset + value.length;
    for (int i = value.offset; i < end; ++i) {
        if (!XMLChar.isSpace(value.ch[i])) {
            reportFatalError("ContentIllegalAtTopLevel");
            return;
        }
    }
}
 
Example #29
Source File: XMLScanner.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Scans surrogates and append them to the specified buffer.
 * <p>
 * <strong>Note:</strong> This assumes the current char has already been
 * identified as a high surrogate.
 *
 * @param buf The StringBuffer to append the read surrogates to.
 * @return True if it succeeded.
 */
protected boolean scanSurrogates(XMLStringBuffer buf)
throws IOException, XNIException {

    int high = fEntityScanner.scanChar(null);
    int low = fEntityScanner.peekChar();
    if (!XMLChar.isLowSurrogate(low)) {
        reportFatalError("InvalidCharInContent",
                new Object[] {Integer.toString(high, 16)});
                return false;
    }
    fEntityScanner.scanChar(null);

    // convert surrogates to supplemental character
    int c = XMLChar.supplemental((char)high, (char)low);

    // supplemental character must be a valid XML character
    if (isInvalid(c)) {
        reportFatalError("InvalidCharInContent",
                new Object[]{Integer.toString(c, 16)});
                return false;
    }

    // fill in the buffer
    buf.append((char)high);
    buf.append((char)low);

    return true;

}
 
Example #30
Source File: XMLSchemaValidator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public boolean characterData(String data, Augmentations augs) {

        fSawText = fSawText || data.length() > 0;

        // REVISIT: this methods basically duplicates implementation of
        //          handleCharacters(). We should be able to reuse some code

        // if whitespace == -1 skip normalization, because it is a complexType
        // or a union type.
        if (fNormalizeData && fWhiteSpace != -1 && fWhiteSpace != XSSimpleType.WS_PRESERVE) {
            // normalize data
            normalizeWhitespace(data, fWhiteSpace == XSSimpleType.WS_COLLAPSE);
            fBuffer.append(fNormalizedStr.ch, fNormalizedStr.offset, fNormalizedStr.length);
        } else {
            if (fAppendBuffer)
                fBuffer.append(data);
        }

        // When it's a complex type with element-only content, we need to
        // find out whether the content contains any non-whitespace character.
        boolean allWhiteSpace = true;
        if (fCurrentType != null
            && fCurrentType.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
            XSComplexTypeDecl ctype = (XSComplexTypeDecl) fCurrentType;
            if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT) {
                // data outside of element content
                for (int i = 0; i < data.length(); i++) {
                    if (!XMLChar.isSpace(data.charAt(i))) {
                        allWhiteSpace = false;
                        fSawCharacters = true;
                        break;
                    }
                }
            }
        }

        return allWhiteSpace;
    }