/** * @return * @see org.w3c.dom.CharacterData#getLength() */ public int getLength() { return getParent().getLength(); }
protected void runTest() throws Throwable { Document document = dbf.newDocumentBuilder().newDocument(); String content = "This is a test string"; Text textNode = document.createTextNode(content); assertEquals(content.length(), textNode.getLength()); } }
public int getLength() { return text().getLength(); }
public static boolean validStringIndexOffset(Node text, int index, int offset) { try { Assert.isTrue(index >= 0 && (index + offset) >= 0 && ((Text) text).getLength() >= (index + offset) && ((Text) text).getLength() >= index); return validText(text); } catch (Exception e) { // "error", "Error in validStringIndex" if (ALERT) { PDPlugin .getAlerts() .confirm( "Alert.EditValidateUtil.Title", "Alert.EditValidateUtil.IndexOffset", e); //$NON-NLS-1$ //$NON-NLS-2$ } if (REPORT) { // "Invalid index or offset in String:" _logger.error("Error.EditValidateUtil.IndexOffset", e); //$NON-NLS-1$ } return false; } }
public static boolean validStringIndex(Node text, int index) { try { Assert.isTrue(index >= 0 && ((Text) text).getLength() >= index); return validText(text); } catch (Exception e) { // "Error", "Error in validStringIndex" if (ALERT) { PDPlugin .getAlerts() .confirm( "Alert.EditValidateUtil.Title", "Alert.EditValidateUtil.StringIndex", e); //$NON-NLS-1$ //$NON-NLS-2$ } if (REPORT) { // "Invalid Index in String:" _logger.error("Error.EditValidateUtil.StringIndex", e); //$NON-NLS-1$ } return false; } }
/** * Get position's container node's editable items number. this is temp * functions for future use. * * @param position * @return */ public int getSize(IDOMPosition position) { EditValidateUtil.validPosition(position); if (position.isText()) { return ((Text) position.getContainerNode()).getLength(); } if (position.getContainerNode().hasChildNodes()) { return position.getContainerNode().getChildNodes().getLength(); } return 0; }
/** * Select the contents within a node * * @param refNodeNode * to select from * @exception RangeException * INVALID_NODE_TYPE_ERR: Raised if <code>refNode</code> * or an ancestor of <code>refNode</code> is an Entity, * Notation or DocumentType node. * @exception DOMException * INVALID_STATE_ERR: Raised if <code>detach()</code> has * already been invoked on this object. */ public void selectNodeContents(Node refNode) throws RangeException, DOMException { if (refNode == null) return; if (refNode.getNodeType() == Node.TEXT_NODE) { Text text = (Text) refNode; setStart(refNode, 0); setEnd(refNode, text.getLength()); } else { NodeList childNodes = refNode.getChildNodes(); int length = (childNodes != null ? childNodes.getLength() : 0); setStart(refNode, 0); setEnd(refNode, length); } }
private static int computeOffset(IDOMPosition pos, Text textNode) { int domOffset = 0; if (pos instanceof DOMRefPosition) { DOMRefPosition rep = (DOMRefPosition) pos; boolean forward = rep.isForward(); Node refNode = rep.getReferenceNode(); if ((refNode != textNode) && forward || (refNode == textNode) && !forward) { domOffset = 0; } else { domOffset = textNode.getLength(); } } else { domOffset = pos.getOffset(); } return domOffset; } }
if (position.isText()) { container = position.getContainerNode(); if (position.getOffset() < ((Text) container).getLength()) { position = DOMPositionHelper.splitText(position); } else {
/** * If text only contains chars '\r' or '\n', it is considered to be * transparent. * * @param node * @return */ public static boolean isTransparentText(Node node) { // should valid non null? Assert.isTrue(node != null); if (node == null || !isText(node)) { return false; } if (!EditValidateUtil.validText(node)) { return false; } Text text = (Text) node; if (text.getLength() == 0) { return true; } String value = text.getNodeValue(); int i = 0; while (i < value.length() && HTMLUtil.isHTMLWhitespace(value.charAt(i))) { i++; } return i == value.length(); }
public static int getLocation(IDOMPosition position) { if (position.getOffset() == 0) { return -1; } if (position.isText()) { if (position.getOffset() == ((Text) position.getContainerNode()) .getLength()) { return 1; } return 0; } if (position.getOffset() == position.getContainerNode() .getChildNodes().getLength()) { return 1; } return 0; }
int splitLength = Math.min(maxRunLength, textNode.getLength()); if (splitLength == textNode.getLength()) { children.add(child); if (splitLength != textNode.getLength()) { newLength = Math.min(newMaxRunLength, textNode.getLength() - nodeIndex); newLength = textNode.getLength() - nodeIndex; runText = textNode.getData().substring(nodeIndex, newLength); nodeIndex += newLength; } while(nodeIndex < textNode.getLength());
int offset = position.getOffset(); if (position.isText()) { int length = ((Text) container).getLength(); Assert.isTrue(offset <= length); } else {
int offset = position.getOffset(); if (EditModelQuery.isText(container)) { int length = ((Text) container).getLength(); Assert.isTrue(offset <= length); } else {
public boolean insertChar() { if (_data.getStringData() == null) { return false; } IDOMPosition position = getOperationPosition(); if (position.isText()) { Text text = EditModelQuery.getInstance().getText(position); text.insertData(getOperationPosition().getOffset(), _data .getCharacterData().toString()); setOperationPosition(new DOMPosition(text, position.getOffset() + 1)); } else { Node refNode = position.getNextSiblingNode(); Text text = _document.createTextNode(_data.getCharacterData() .toString()); position.getContainerNode().insertBefore(text, refNode); setOperationPosition(new DOMPosition(text, text.getLength())); } return true; }
public boolean insertString() { String content = _data.getStringData(); if (content != null) { IDOMPosition position = getOperationPosition(); if (position.isText()) { Text text = EditModelQuery.getInstance().getText(position); text.insertData(getOperationPosition().getOffset(), content); setOperationPosition(new DOMPosition(text, position.getOffset() + content.length())); } else { Node refNode = position.getNextSiblingNode(); Text text = _document.createTextNode(content); position.getContainerNode().insertBefore(text, refNode); setOperationPosition(new DOMPosition(text, text.getLength())); } return true; } return false; }
} catch (Exception ex) { r.setStart(node, ((Text) node).getLength() - 1);