Java Code Examples for org.apache.xerces.util.XMLChar#isInvalid()

The following examples show how to use org.apache.xerces.util.XMLChar#isInvalid() . 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: TmxScanner2.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
private boolean scanSurrogates(XMLStringBuffer buf) throws IOException, TmxEndEntityException {
	int high = entityScanner.scanChar();
	int low = entityScanner.peekChar();
	if (!XMLChar.isLowSurrogate(low)) {
		error("invalid char in content");
		return false;
	}

	entityScanner.scanChar();

	int c = XMLChar.supplemental((char) high, (char) low);

	if (XMLChar.isInvalid(c)) {
		error("invalid char in content");
		return false;
	}

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

	return true;
}
 
Example 2
Source File: TmxScanner.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
private boolean scanSurrogates(XMLStringBuffer buf) throws IOException {
	int high = entityScanner.scanChar();
	int low = entityScanner.peekChar();
	if (!XMLChar.isLowSurrogate(low)) {
		error("invalid char in content");
		return false;
	}
	entityScanner.scanChar();

	int c = XMLChar.supplemental((char) high, (char) low);

	// supplemental character must be a valid XML character
	if (XMLChar.isInvalid(c)) {
		error("invalid char in content");
		return false;
	}

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

	return true;
}
 
Example 3
Source File: TmxScanner2.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
protected void scanExternalID(String[] identifiers, boolean optionalSystemId) throws IOException,
		TmxEndEntityException, RepairableException {

	String systemId = null;
	String publicId = null;
	if (entityScanner.skipString("PUBLIC")) {
		if (!entityScanner.skipSpaces()) {
			newRepairableException("SpaceRequiredAfterPUBLIC");
		}
		scanPubidLiteral(fString);
		publicId = fString.toString();

		if (!entityScanner.skipSpaces() && !optionalSystemId) {
			newRepairableException("SpaceRequiredBetweenPublicAndSystem");
		}
	}

	if (publicId != null || entityScanner.skipString("SYSTEM")) {
		if (publicId == null && !entityScanner.skipSpaces()) {
			newRepairableException("SpaceRequiredAfterSYSTEM");
		}
		int quote = entityScanner.peekChar();
		if (quote != '\'' && quote != '"') {
			if (publicId != null && optionalSystemId) {
				// looks like we don't have any system id
				// simply return the public id
				identifiers[0] = null;
				identifiers[1] = publicId;
				return;
			}
			newRepairableException("QuoteRequiredInSystemID");
		}
		entityScanner.scanChar();
		XMLString ident = fString;
		if (entityScanner.scanLiteral(quote, ident) != quote) {
			fStringBuffer.clear();
			do {
				fStringBuffer.append(ident);
				int c = entityScanner.peekChar();
				if (XMLChar.isMarkup(c) || c == ']') {
					fStringBuffer.append((char) entityScanner.scanChar());
				} else if (XMLChar.isHighSurrogate(c)) {
					scanSurrogates(fStringBuffer);
				} else if (XMLChar.isInvalid(c)) {
					newRepairableException("InvalidCharInSystemID");
					entityScanner.scanChar();
				}
			} while (entityScanner.scanLiteral(quote, ident) != quote);
			fStringBuffer.append(ident);
			ident = fStringBuffer;
		}
		systemId = ident.toString();
		if (!entityScanner.skipChar((char) quote)) {
			newRepairableException("SystemIDUnterminated");
		}
	}

	// store result in array
	identifiers[0] = systemId;
	identifiers[1] = publicId;
}
 
Example 4
Source File: TmxScanner2.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
private String scanPseudoAttribute(boolean scanningTextDecl, XMLString value) throws IOException,
		RepairableException, TmxEndEntityException {
	String name = entityScanner.scanName();
	if (name.isEmpty()) {
		newRepairableException("not found Pseudo Attribute name", entityScanner.getLineNumber(),
				entityScanner.getOffsetNumber());
	}
	entityScanner.skipDeclSpaces();
	if (!entityScanner.skipChar('=')) {
		newRepairableException("not found '=' when scan Pseudo Attribute", entityScanner.getLineNumber(),
				entityScanner.getOffsetNumber());
	}
	entityScanner.skipDeclSpaces();
	int quote = entityScanner.peekChar();
	if (quote != '\'' && quote != '"') {
		newRepairableException("not found 'quote' when scan Pseudo Attribute", entityScanner.getLineNumber(),
				entityScanner.getOffsetNumber());
	}
	entityScanner.scanChar();
	int c = entityScanner.scanLiteral(quote, value);
	if (c != quote) {
		fStringBuffer2.clear();
		do {
			fStringBuffer2.append(value);
			if (c != -1) {
				if (c == '&' || c == '%' || c == '<' || c == ']') {
					fStringBuffer2.append((char) entityScanner.scanChar());
				}
				// REVISIT: Even if you could reliably read non-ASCII chars
				// why bother scanning for surrogates here? Only ASCII chars
				// match the productions in XMLDecls and TextDecls. -- mrglavas
				else if (XMLChar.isHighSurrogate(c)) {
					scanSurrogates(fStringBuffer2);
				} else if (XMLChar.isInvalid(c)) {
					entityScanner.scanChar();
					// TODO should we report error, or skip this char silence?
					// error("Invalid Char in xml declaration : '&#" + Integer.toHexString(c) + "'");
				}
			}
			c = entityScanner.scanLiteral(quote, value);
		} while (c != quote);
		fStringBuffer2.append(value);
		value.setValues(fStringBuffer2);
	}
	if (!entityScanner.skipChar((char) quote)) {
		throw new RepairableException("not found close quote");
	}
	return name;
}
 
Example 5
Source File: TmxScanner2.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
private void scanPIData(String target, XMLString xs) throws IOException, TmxEndEntityException {
	// check target
	if (target.length() == 3) {
		char c0 = Character.toLowerCase(target.charAt(0));
		char c1 = Character.toLowerCase(target.charAt(1));
		char c2 = Character.toLowerCase(target.charAt(2));
		if (c0 == 'x' && c1 == 'm' && c2 == 'l') {
			// TODO 非法命名
			return;
		}
	}
	// spaces
	if (!entityScanner.skipSpaces()) {
		if (entityScanner.skipString("?>")) {
			// we found the end, there is no data
			xs.clear();
			return;
		} else {
			if (entityScanner.peekChar() == ':') {
				entityScanner.scanChar();
				XMLStringBuffer colonName = new XMLStringBuffer(target);
				colonName.append(':');
				String str = entityScanner.scanName();
				if (str != null)
					colonName.append(str);
				// TODO reportFatalError("ColonNotLegalWithNS", new Object[] {colonName.toString()});
				entityScanner.skipSpaces();
			} else {
				// TODO reportFatalError("SpaceRequiredInPI", null);
			}
		}
	}

	fStringBuffer.clear();
	// data
	if (entityScanner.scanData("?>", fStringBuffer)) {
		do {
			int c = entityScanner.peekChar();
			if (c != -1) {
				if (XMLChar.isHighSurrogate(c)) {
					scanSurrogates(fStringBuffer);
				} else if (XMLChar.isInvalid(c)) {
					// reportFatalError("InvalidCharInPI",
					// new Object[]{Integer.toHexString(c)});
					entityScanner.scanChar();
				}
			}
		} while (entityScanner.scanData("?>", fStringBuffer));
	}
	xs.setValues(fStringBuffer);
}
 
Example 6
Source File: TmxScanner.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
private void scanPIData(String target, XMLString xs) throws IOException {

		// check target
		if (target.length() == 3) {
			char c0 = Character.toLowerCase(target.charAt(0));
			char c1 = Character.toLowerCase(target.charAt(1));
			char c2 = Character.toLowerCase(target.charAt(2));
			if (c0 == 'x' && c1 == 'm' && c2 == 'l') {
				// TODO
				// reportFatalError("ReservedPITarget", null);
			}
		}

		// spaces
		if (!entityScanner.skipSpaces()) {
			if (entityScanner.skipString("?>")) {
				// we found the end, there is no data
				xs.clear();
				return;
			} else {
				if (entityScanner.peekChar() == ':') {
					entityScanner.scanChar();
					XMLStringBuffer colonName = new XMLStringBuffer(target);
					colonName.append(':');
					String str = entityScanner.scanName();
					if (str != null)
						colonName.append(str);
					// TODO
					// reportFatalError("ColonNotLegalWithNS", new Object[] {colonName.toString()});
					entityScanner.skipSpaces();
				} else {
					// TODO
					// if there is data there should be some space
					// reportFatalError("SpaceRequiredInPI", null);
				}
			}
		}

		fStringBuffer.clear();
		// data
		if (entityScanner.scanData("?>", fStringBuffer)) {
			do {
				int c = entityScanner.peekChar();
				if (c != -1) {
					if (XMLChar.isHighSurrogate(c)) {
						scanSurrogates(fStringBuffer);
					} else if (XMLChar.isInvalid(c)) {
						// reportFatalError("InvalidCharInPI",
						// new Object[]{Integer.toHexString(c)});
						entityScanner.scanChar();
					}
				}
			} while (entityScanner.scanData("?>", fStringBuffer));
		}
		xs.setValues(fStringBuffer);
	}
 
Example 7
Source File: TmxScanner.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
private String scanPseudoAttribute(boolean scanningTextDecl, XMLString value) throws IOException {
	String name = entityScanner.scanName();
	if (name == null) {
		error("not found paseudo attribute");
	}
	entityScanner.skipDeclSpaces();
	if (!entityScanner.skipChar('=')) {
		error("not found '='");
	}
	entityScanner.skipDeclSpaces();
	int quote = entityScanner.peekChar();
	if (quote != '\'' && quote != '"') {
		error("not found quote when scan pseudo attribute");
	}
	entityScanner.scanChar();
	int c = entityScanner.scanLiteral(quote, value);
	if (c != quote) {
		fStringBuffer2.clear();
		do {
			fStringBuffer2.append(value);
			if (c != -1) {
				if (c == '&' || c == '%' || c == '<' || c == ']') {
					fStringBuffer2.append((char) entityScanner.scanChar());
				}
				// REVISIT: Even if you could reliably read non-ASCII chars
				// why bother scanning for surrogates here? Only ASCII chars
				// match the productions in XMLDecls and TextDecls. -- mrglavas
				else if (XMLChar.isHighSurrogate(c)) {
					scanSurrogates(fStringBuffer2);
				} else if (XMLChar.isInvalid(c)) {
					String key = scanningTextDecl ? "InvalidCharInTextDecl" : "InvalidCharInXMLDecl";
					error("invalid char '&#" + Integer.toHexString(c) + "'");
					// reportFatalError(key,
					// new Object[] {Integer.toString(c, 16)});
					entityScanner.scanChar();
				}
			}
			c = entityScanner.scanLiteral(quote, value);
		} while (c != quote);
		fStringBuffer2.append(value);
		value.setValues(fStringBuffer2);
	}
	if (!entityScanner.skipChar((char) quote)) {
		error("not found close quote");
	}

	// return
	return name;
}