Java Code Examples for org.apache.xerces.xni.XMLString

The following examples show how to use org.apache.xerces.xni.XMLString. These examples are extracted from open source projects. 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 Project: lemminx   Source File: XMLModelHandler.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void processingInstruction(String target, XMLString data, Augmentations augs) throws XNIException {
	if (XMLModelConstants.XML_MODEL_PI.equals(target)) {
		XMLModelDeclaration model = XMLModelDeclaration.parse(data);
		XMLModelValidator validator = createValidator(model);
		if (validator != null) {
			validator.reset(configuration);
			validator.setHref(model.getHref());
			if (xmlModelValidators == null) {
				xmlModelValidators = new ArrayList<>();
			}
			xmlModelValidators.add(validator);
		}
	}

	if (documentHandler != null) {
		documentHandler.processingInstruction(target, data, augs);
	}
}
 
Example 2
Source Project: tmxeditor8   Source File: TmxScanner2.java    License: GNU General Public License v2.0 6 votes vote down vote up
private 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];
		// Performance: For XML 1.0 documents take advantage of
		// the fact that the only legal characters below 0x20
		// are 0x09 (TAB), 0x0A (LF) and 0x0D (CR). Since we've
		// already determined the well-formedness of these
		// characters it is sufficient (and safe) to check
		// against 0x20. -- mrglavas
		if (c < 0x20) {
			if (c == 0x09 || c == 0x0d || c == 0x0a) {
				continue;
			}
			value.ch[i] = ' ';
			illegalCharacter = true;
		}
	}
}
 
Example 3
Source Project: tmxeditor8   Source File: TmxScanner2.java    License: GNU General Public License v2.0 6 votes vote down vote up
private int isUnchangedByNormalization(XMLString value) {
	int end = value.offset + value.length;
	for (int i = value.offset; i < end; ++i) {
		int c = value.ch[i];
		// Performance: For XML 1.0 documents take advantage of
		// the fact that the only legal characters below 0x20
		// are 0x09 (TAB), 0x0A (LF) and 0x0D (CR). Since we've
		// already determined the well-formedness of these
		// characters it is sufficient (and safe) to check
		// against 0x20. -- mrglavas
		if (c < 0x20) {
			return i - value.offset;
		}
	}
	return -1;
}
 
Example 4
Source Project: tmxeditor8   Source File: CorrectWriter.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void write(XMLString content) throws IOException, RepairableException {
	if (stack.fSize == 0) {
		return;
	}
	QName tq = new QName();
	stack.lastElement(tq);
	record.textAccept = schema.isTextAccept(tq, content);
	if (record.textAccept) {
		record.xmls.append(content);
	} else {
		record.textAccept = false;
		record.xmls.clear();
		record.tuset = false;
		throw new RepairableException(
				MessageFormat.format(Messages.getString("tmxeditor.tmxFileValidator.autofix.errorcode"), tq.rawname, ""));
	}
}
 
Example 5
Source Project: tmxeditor8   Source File: TmxScanner.java    License: GNU General Public License v2.0 6 votes vote down vote up
private int isUnchangedByNormalization(XMLString value) {
	int end = value.offset + value.length;
	for (int i = value.offset; i < end; ++i) {
		int c = value.ch[i];
		// Performance: For XML 1.0 documents take advantage of
		// the fact that the only legal characters below 0x20
		// are 0x09 (TAB), 0x0A (LF) and 0x0D (CR). Since we've
		// already determined the well-formedness of these
		// characters it is sufficient (and safe) to check
		// against 0x20. -- mrglavas
		if (c < 0x20) {
			return i - value.offset;
		}
	}
	return -1;
}
 
Example 6
Source Project: lemminx   Source File: XMLModelHandler.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void comment(XMLString text, Augmentations augs) throws XNIException {
	if (xmlModelValidators != null) {
		for (XMLModelValidator validator : xmlModelValidators) {
			validator.comment(text, augs);
		}
	}

	if (documentHandler != null) {
		documentHandler.comment(text, augs);
	}
}
 
Example 7
Source Project: lemminx   Source File: XMLModelHandler.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void characters(XMLString text, Augmentations augs) throws XNIException {
	if (xmlModelValidators != null) {
		for (XMLModelValidator validator : xmlModelValidators) {
			validator.characters(text, augs);
		}
	}

	if (documentHandler != null) {
		documentHandler.characters(text, augs);
	}
}
 
Example 8
Source Project: lemminx   Source File: XMLModelHandler.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException {
	if (xmlModelValidators != null) {
		for (XMLModelValidator validator : xmlModelValidators) {
			validator.ignorableWhitespace(text, augs);
		}
	}

	if (documentHandler != null) {
		documentHandler.ignorableWhitespace(text, augs);
	}
}
 
Example 9
Source Project: lemminx   Source File: CMDTDDocument.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void internalEntityDecl(String name, XMLString text, XMLString nonNormalizedText, Augmentations augs)
		throws XNIException {
	super.internalEntityDecl(name, text, nonNormalizedText, augs);
	try {
		entities.add(new ScannedDTDEntityDecl(name, text.toString(), fEntityManager.getCurrentEntity()));
	} catch (Exception e) {
		LOGGER.log(Level.SEVERE, "Error while extracting information for the internal entity '" + name + "'", e);
	}
}
 
Example 10
Source Project: lemminx   Source File: CMDTDDocument.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void attributeDecl(String elementName, String attributeName, String type, String[] enumeration,
		String defaultType, XMLString defaultValue, XMLString nonNormalizedDefaultValue, Augmentations augs)
		throws XNIException {
	if (comment != null) {
		nodeInfo = new DTDNodeInfo();
		nodeInfo.setComment(comment);
		attributes.put(attributeName, nodeInfo);
	}
	super.attributeDecl(elementName, attributeName, type, enumeration, defaultType, defaultValue,
			nonNormalizedDefaultValue, augs);
}
 
Example 11
Source Project: lemminx   Source File: CMDTDDocument.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void comment(XMLString text, Augmentations augs) throws XNIException {
	if (text != null) {
		comment = text.toString();
	}
	super.comment(text, augs);
}
 
Example 12
Source Project: cc-dbp   Source File: HTMLTagBalancer.java    License: Apache License 2.0 5 votes vote down vote up
/** Comment. */
public void comment(XMLString text, Augmentations augs) throws XNIException {
    fSeenAnything = true;
    consumeEarlyTextIfNeeded();
    if (fDocumentHandler != null) {
        fDocumentHandler.comment(text, augs);
    }
}
 
Example 13
Source Project: cc-dbp   Source File: HTMLTagBalancer.java    License: Apache License 2.0 5 votes vote down vote up
/** Processing instruction. */
public void processingInstruction(String target, XMLString data,
                                  Augmentations augs) throws XNIException {
    fSeenAnything = true;
    consumeEarlyTextIfNeeded();
    if (fDocumentHandler != null) {
        fDocumentHandler.processingInstruction(target, data, augs);
    }
}
 
Example 14
@Override
public void ignorableWhitespace(XMLString arg0, Augmentations arg1)
        throws XNIException {
  if(DEBUG_UNUSED) {
    Out.println("ignorableWhitespace: " + arg0);
  }
}
 
Example 15
Source Project: lams   Source File: ScriptFilter.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void characters( XMLString text, Augmentations augs ) throws XNIException {
    if (_activeScriptBlock != null) {
        _activeScriptBlock.append( text.ch, text.offset, text.length );
    } else {
        super.characters( text, augs );
    }
}
 
Example 16
Source Project: tmxeditor8   Source File: TmxSchema.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean isTextAccept(QName qname, XMLString content) {
	boolean spaces = true;
	for (int i = content.offset; i < content.offset + content.length; i++) {
		spaces = spaces &&  XMLChar.isSpace(content.ch[i]);
	}
	if (spaces) {
		return true;
	}
	return acceptText.containsSymbol(qname.rawname);
}
 
Example 17
Source Project: tmxeditor8   Source File: TmxScanner2.java    License: GNU General Public License v2.0 5 votes vote down vote up
private boolean scanPubidLiteral(XMLString literal) throws TmxEndEntityException, IOException, RepairableException {
	int quote = entityScanner.scanChar();
	if (quote != '\'' && quote != '"') {
		newRepairableException("QuoteRequiredInPublicID");
		return false;
	}

	fStringBuffer.clear();
	// skip leading whitespace
	boolean skipSpace = true;
	boolean dataok = true;
	while (true) {
		int c = entityScanner.scanChar();
		if (c == ' ' || c == '\n' || c == '\r') {
			if (!skipSpace) {
				// take the first whitespace as a space and skip the others
				fStringBuffer.append(' ');
				skipSpace = true;
			}
		} else if (c == quote) {
			if (skipSpace) {
				// if we finished on a space let's trim it
				fStringBuffer.length--;
			}
			literal.setValues(fStringBuffer);
			break;
		} else if (XMLChar.isPubid(c)) {
			fStringBuffer.append((char) c);
			skipSpace = false;
		} else if (c == -1) {
			newRepairableException("PublicIDUnterminated");
			return false;
		} else {
			dataok = false;
			newRepairableException("InvalidCharInPublicID");
		}
	}
	return dataok;
}
 
Example 18
Source Project: tmxeditor8   Source File: TmxScanner.java    License: GNU General Public License v2.0 5 votes vote down vote up
private 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];
		// Performance: For XML 1.0 documents take advantage of
		// the fact that the only legal characters below 0x20
		// are 0x09 (TAB), 0x0A (LF) and 0x0D (CR). Since we've
		// already determined the well-formedness of these
		// characters it is sufficient (and safe) to check
		// against 0x20. -- mrglavas
		if (c < 0x20) {
			value.ch[i] = ' ';
		}
	}
}
 
Example 19
Source Project: tmxeditor8   Source File: TmxScanner.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void normalizeWhitespace(XMLString value) {
	int end = value.offset + value.length;
	for (int i = value.offset; i < end; ++i) {
		int c = value.ch[i];
		// Performance: For XML 1.0 documents take advantage of
		// the fact that the only legal characters below 0x20
		// are 0x09 (TAB), 0x0A (LF) and 0x0D (CR). Since we've
		// already determined the well-formedness of these
		// characters it is sufficient (and safe) to check
		// against 0x20. -- mrglavas
		if (c < 0x20) {
			value.ch[i] = ' ';
		}
	}
}
 
Example 20
Source Project: lemminx   Source File: XMLModelDeclaration.java    License: Eclipse Public License 2.0 4 votes vote down vote up
public static XMLModelDeclaration parse(XMLString data) {
	return parse(data.ch, data.offset, data.length);
}
 
Example 21
public void characters(XMLString xmlString, Augmentations augmentations)
        throws XNIException {
    super.characters(xmlString, augmentations);
    buffer.append(" ");
    buffer.append(xmlString.toString());
}
 
Example 22
Source Project: cc-dbp   Source File: HTMLTagBalancer.java    License: Apache License 2.0 4 votes vote down vote up
/** Characters. */
public void characters(final XMLString text, final Augmentations augs) throws XNIException {
    // check for end of document
    if (fSeenRootElementEnd) {
        return;
    }

	if (fElementStack.top == 0 && !fDocumentFragment) {
		// character before first opening tag
		lostText_.add(text, augs);
		return;
	}

    // is this text whitespace?
    boolean whitespace = true;
    for (int i = 0; i < text.length; i++) {
        if (!Character.isWhitespace(text.ch[text.offset + i])) {
            whitespace = false;
            break;
        }
    }

    if (!fDocumentFragment) {
        // handle bare characters
        if (!fSeenRootElement) {
            if (whitespace) {
                return;
            }
            forceStartBody();
        }
        
        if (whitespace && (fElementStack.top < 2 || endElementsBuffer_.size() == 1)) {
        	// ignore spaces directly within <html>
        	return;
        }

        // handle character content in head
        // NOTE: This frequently happens when the document looks like:
        //       <title>Title</title>
        //       And here's some text.
        else if (!whitespace) {
            Info info = fElementStack.peek();
            if (info.element.code == HTMLElements.HEAD ||
                info.element.code == HTMLElements.HTML) {
                String hname = modifyName("head", fNamesElems);
                String bname = modifyName("body", fNamesElems);
                if (fReportErrors) {
                    fErrorReporter.reportWarning("HTML2009", new Object[]{hname,bname});
                }
                forceStartBody();
            }
        }
    }

    // call handler
    if (fDocumentHandler != null) {
        fDocumentHandler.characters(text, augs);
    }

}
 
Example 23
Source Project: cc-dbp   Source File: HTMLTagBalancer.java    License: Apache License 2.0 4 votes vote down vote up
/** Ignorable whitespace. */
public void ignorableWhitespace(XMLString text, Augmentations augs)
    throws XNIException {
    characters(text, augs);
}
 
Example 24
/**
 * Called when the parser encounters character or CDATA content.
 * Characters may be reported in more than one chunk, so we gather all
 * contiguous chunks together and process them in one block.
 */
@Override
public void characters(XMLString text, Augmentations augs)
        throws XNIException {
  if(!readCharacterStatus) {
    if(reposInfo != null) {
      HTMLEventInfo evInfo = (augs == null) ? null : (HTMLEventInfo)augs
              .getItem(AUGMENTATIONS);
      if(evInfo == null) {
        Err.println("Warning: could not determine proper repositioning "
                + "info for character chunk \""
                + new String(text.ch, text.offset, text.length)
                + "\" near offset " + charactersStartOffset
                + ".  Save preserving format may give incorret results.");
      }
      else {
        // NekoHTML numbers lines and columns from 1, not 0
        int line = evInfo.getBeginLineNumber() - 1;
        int col = evInfo.getBeginColumnNumber() - 1;
        charactersStartOffset = lineOffsets[line] + col;
        if(DEBUG_CHARACTERS) {
          Out.println("characters: line = " + line + " (offset " +
              lineOffsets[line] + "), col = " + col + " : file offset = " +
              charactersStartOffset);
        }
      }
    }

    contentBuffer = new StringBuilder();
  }
  readCharacterStatus = true;

  boolean canAppendWS = (contentBuffer.length() == 0 || !Character
          .isWhitespace(contentBuffer.charAt(contentBuffer.length() - 1)));
  // we must collapse
  // whitespace down to a single space, to mirror the normal
  // HtmlDocumentFormat.
  for(int i = text.offset; i < text.offset + text.length; ++i) {
    if(!Character.isWhitespace(text.ch[i])) {
      contentBuffer.append(text.ch[i]);
      canAppendWS = true;
    }
    else {
      if(canAppendWS) {
        contentBuffer.append(' ');
        canAppendWS = false;
      }
    }
  }
}
 
Example 25
@Override
public void processingInstruction(String target, XMLString data,
        Augmentations augs) throws XNIException {
  charactersAction();
}
 
Example 26
@Override
public void comment(XMLString content,
        Augmentations augs) throws XNIException {
  charactersAction();
}
 
Example 27
Source Project: tmxeditor8   Source File: TmxScanner2.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected int scanContent() throws IOException, TmxEndEntityException, RepairableException {

		int line = entityScanner.getLineNumber();
		int column = entityScanner.getOffsetNumber();

		XMLString content = fTempString;
		int c = entityScanner.scanContent(content);
		if (c == '\r') {
			// happens when there is the character reference &#13;
			entityScanner.scanChar();
			stringBuffer.clear();
			stringBuffer.append(content);
			stringBuffer.append((char) c);
			content = stringBuffer;
			c = -1;
		}

		// String str = new String(content.ch, content.offset, content.length);
		if (c == ']' && fTempString.length == 0) {
			stringBuffer.clear();
			stringBuffer.append((char) entityScanner.scanChar());
			// remember where we are in case we get an endEntity before we
			// could flush the buffer out - this happens when we're parsing an
			// entity which ends with a ]
			// fInScanContent = true;
			//
			// We work on a single character basis to handle cases such as:
			// ']]]>' which we might otherwise miss.
			//
			if (entityScanner.skipChar(']')) {
				stringBuffer.append(']');
				while (entityScanner.skipChar(']')) {
					stringBuffer.append(']');
				}
				if (entityScanner.skipChar('>')) {
					// TODO reportFatalError("CDEndInContent", null);
				}
			}
			// TODO fInScanContent = false;
			c = -1;
		}

		try {
			cwriter.write(content);
		} catch (RepairableException e) {
			e.setColumn(column);
			e.setRow(line);
			throw e;
		}

		return c;
	}
 
Example 28
Source Project: tmxeditor8   Source File: TmxScanner2.java    License: 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 29
Source Project: tmxeditor8   Source File: TmxScanner2.java    License: 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 30
Source Project: tmxeditor8   Source File: TmxScanner2.java    License: 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);
}