Java Code Examples for com.sun.org.apache.xerces.internal.util.XMLChar#isSpace()
The following examples show how to use
com.sun.org.apache.xerces.internal.util.XMLChar#isSpace() .
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: XML11DTDScannerImpl.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Normalize whitespace in an XMLString converting all whitespace * characters to space characters. */ protected void normalizeWhitespace(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)) { value.ch[i] = ' '; } } }
Example 2
Source File: CharacterEvent.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private void checkWhiteSpace(){ //for now - remove dependancy of XMLChar if(fData != null && fData.length() >0 ){ fIsSpace = true; for(int i=0;i<fData.length();i++){ if(!XMLChar.isSpace(fData.charAt(i))){ fIsSpace = false; break; } } } }
Example 3
Source File: XML11DTDScannerImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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 4
Source File: XMLSchemaValidator.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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 5
Source File: XMLStreamReaderImpl.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * 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 6
Source File: XML11DocumentScannerImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * 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 7
Source File: XML11DTDScannerImpl.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Normalize whitespace in an XMLString converting all whitespace * characters to space characters. */ protected void normalizeWhitespace(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)) { value.ch[i] = ' '; } } }
Example 8
Source File: XML11DocumentScannerImpl.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * 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 9
Source File: XMLSchemaValidator.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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 10
Source File: SchemaDOMParser.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * 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 11
Source File: XMLSchemaValidator.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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 12
Source File: XML11DTDScannerImpl.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * 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 13
Source File: XMLSchemaValidator.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
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 14
Source File: XMLSchemaValidator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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 15
Source File: XML11DocumentScannerImpl.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * 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 16
Source File: SchemaDOMParser.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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 17
Source File: XMLEntityScanner.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Skips space characters appearing immediately on the input that would * match non-terminal S (0x09, 0x0A, 0x0D, 0x20) before end of line * normalization is performed. This is useful when scanning structures * such as the XMLDecl and TextDecl that can only contain US-ASCII * characters. * <p> * <strong>Note:</strong> The characters are consumed only if they would * match non-terminal S before end of line normalization is performed. * * @return Returns true if at least one space character was skipped. * * @throws IOException Thrown if i/o error occurs. * @throws EOFException Thrown on end of file. * * @see com.sun.org.apache.xerces.internal.util.XMLChar#isSpace */ public final boolean skipDeclSpaces() throws IOException { if (DEBUG_BUFFER) { System.out.print("(skipDeclSpaces: "); //XMLEntityManager.print(fCurrentEntity); System.out.println(); } // load more characters, if needed if (fCurrentEntity.position == fCurrentEntity.count) { load(0, true); } // skip spaces int c = fCurrentEntity.ch[fCurrentEntity.position]; if (XMLChar.isSpace(c)) { boolean external = fCurrentEntity.isExternal(); do { boolean entityChanged = false; // handle newlines if (c == '\n' || (external && c == '\r')) { fCurrentEntity.lineNumber++; fCurrentEntity.columnNumber = 1; if (fCurrentEntity.position == fCurrentEntity.count - 1) { fCurrentEntity.ch[0] = (char)c; entityChanged = load(1, true); if (!entityChanged) // the load change the position to be 1, // need to restore it when entity not changed fCurrentEntity.position = 0; } if (c == '\r' && external) { // REVISIT: Does this need to be updated to fix the // #x0D ^#x0A newline normalization problem? -Ac if (fCurrentEntity.ch[++fCurrentEntity.position] != '\n') { fCurrentEntity.position--; } } /*** NEWLINE NORMALIZATION *** * else { * if (fCurrentEntity.ch[fCurrentEntity.position + 1] == '\r' * && external) { * fCurrentEntity.position++; * } * } * /***/ } else { fCurrentEntity.columnNumber++; } // load more characters, if needed if (!entityChanged) fCurrentEntity.position++; if (fCurrentEntity.position == fCurrentEntity.count) { load(0, true); } } while (XMLChar.isSpace(c = fCurrentEntity.ch[fCurrentEntity.position])); if (DEBUG_BUFFER) { System.out.print(")skipDeclSpaces: "); // XMLEntityManager.print(fCurrentEntity); System.out.println(" -> true"); } return true; } // no spaces were found if (DEBUG_BUFFER) { System.out.print(")skipDeclSpaces: "); //XMLEntityManager.print(fCurrentEntity); System.out.println(" -> false"); } return false; }
Example 18
Source File: XMLSchemaValidator.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Normalize whitespace in an XMLString according to the rules defined * in XML Schema specifications. * @param value The string to normalize. * @param collapse replace or collapse */ private void normalizeWhitespace(XMLString value, boolean collapse) { boolean skipSpace = collapse; boolean sawNonWS = false; boolean leading = false; boolean trailing = false; char c; int size = value.offset + value.length; // ensure the ch array is big enough if (fNormalizedStr.ch == null || fNormalizedStr.ch.length < value.length + 1) { fNormalizedStr.ch = new char[value.length + 1]; } // don't include the leading ' ' for now. might include it later. fNormalizedStr.offset = 1; fNormalizedStr.length = 1; for (int i = value.offset; i < size; i++) { c = value.ch[i]; if (XMLChar.isSpace(c)) { if (!skipSpace) { // take the first whitespace as a space and skip the others fNormalizedStr.ch[fNormalizedStr.length++] = ' '; skipSpace = collapse; } if (!sawNonWS) { // this is a leading whitespace, record it leading = true; } } else { fNormalizedStr.ch[fNormalizedStr.length++] = c; skipSpace = false; sawNonWS = true; } } if (skipSpace) { if (fNormalizedStr.length > 1) { // if we finished on a space trim it but also record it fNormalizedStr.length--; trailing = true; } else if (leading && !fFirstChunk) { // if all we had was whitespace we skipped record it as // trailing whitespace as well trailing = true; } } if (fNormalizedStr.length > 1) { if (!fFirstChunk && (fWhiteSpace == XSSimpleType.WS_COLLAPSE)) { if (fTrailing) { // previous chunk ended on whitespace // insert whitespace fNormalizedStr.offset = 0; fNormalizedStr.ch[0] = ' '; } else if (leading) { // previous chunk ended on character, // this chunk starts with whitespace fNormalizedStr.offset = 0; fNormalizedStr.ch[0] = ' '; } } } // The length includes the leading ' '. Now removing it. fNormalizedStr.length -= fNormalizedStr.offset; fTrailing = trailing; if (trailing || sawNonWS) fFirstChunk = false; }
Example 19
Source File: XMLDTDValidator.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
protected boolean isSpace(int c) { return XMLChar.isSpace(c); }
Example 20
Source File: XMLSchemaValidator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Normalize whitespace in an XMLString according to the rules defined * in XML Schema specifications. * @param value The string to normalize. * @param collapse replace or collapse */ private void normalizeWhitespace(XMLString value, boolean collapse) { boolean skipSpace = collapse; boolean sawNonWS = false; boolean leading = false; boolean trailing = false; char c; int size = value.offset + value.length; // ensure the ch array is big enough if (fNormalizedStr.ch == null || fNormalizedStr.ch.length < value.length + 1) { fNormalizedStr.ch = new char[value.length + 1]; } // don't include the leading ' ' for now. might include it later. fNormalizedStr.offset = 1; fNormalizedStr.length = 1; for (int i = value.offset; i < size; i++) { c = value.ch[i]; if (XMLChar.isSpace(c)) { if (!skipSpace) { // take the first whitespace as a space and skip the others fNormalizedStr.ch[fNormalizedStr.length++] = ' '; skipSpace = collapse; } if (!sawNonWS) { // this is a leading whitespace, record it leading = true; } } else { fNormalizedStr.ch[fNormalizedStr.length++] = c; skipSpace = false; sawNonWS = true; } } if (skipSpace) { if (fNormalizedStr.length > 1) { // if we finished on a space trim it but also record it fNormalizedStr.length--; trailing = true; } else if (leading && !fFirstChunk) { // if all we had was whitespace we skipped record it as // trailing whitespace as well trailing = true; } } if (fNormalizedStr.length > 1) { if (!fFirstChunk && (fWhiteSpace == XSSimpleType.WS_COLLAPSE)) { if (fTrailing) { // previous chunk ended on whitespace // insert whitespace fNormalizedStr.offset = 0; fNormalizedStr.ch[0] = ' '; } else if (leading) { // previous chunk ended on character, // this chunk starts with whitespace fNormalizedStr.offset = 0; fNormalizedStr.ch[0] = ' '; } } } // The length includes the leading ' '. Now removing it. fNormalizedStr.length -= fNormalizedStr.offset; fTrailing = trailing; if (trailing || sawNonWS) fFirstChunk = false; }