/** * @serialData Serialized fields. Convert Maps to Hashtables and Lists * to Vectors for backward compatibility. */ private void writeObject(ObjectOutputStream out) throws IOException { // Convert Maps to Hashtables, Lists to Vectors Vector<NodeIterator> it = (iterators == null)? null : new Vector<>(iterators); Vector<Range> r = (ranges == null)? null : new Vector<>(ranges); Hashtable<NodeImpl, Vector<LEntry>> el = null; if (eventListeners != null) { el = new Hashtable<>(); for (Map.Entry<NodeImpl, List<LEntry>> e : eventListeners.entrySet()) { el.put(e.getKey(), new Vector<>(e.getValue())); } } // Write serialized fields ObjectOutputStream.PutField pf = out.putFields(); pf.put("iterators", it); pf.put("ranges", r); pf.put("eventListeners", el); pf.put("mutationEvents", mutationEvents); out.writeFields(); }
@SuppressWarnings("unchecked") private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { // We have to read serialized fields first. ObjectInputStream.GetField gf = in.readFields(); Vector<NodeIterator> it = (Vector<NodeIterator>)gf.get("iterators", null); Vector<Range> r = (Vector<Range>)gf.get("ranges", null); Hashtable<NodeImpl, Vector<LEntry>> el = (Hashtable<NodeImpl, Vector<LEntry>>)gf.get("eventListeners", null); mutationEvents = gf.get("mutationEvents", false); //convert Hashtables back to HashMaps and Vectors to Lists if (it != null) iterators = new ArrayList<>(it); if (r != null) ranges = new ArrayList<>(r); if (el != null) { eventListeners = new HashMap<>(); for (Map.Entry<NodeImpl, Vector<LEntry>> e : el.entrySet()) { eventListeners.put(e.getKey(), new ArrayList<>(e.getValue())); } } }
public Range getSelectionRange() { if (this.dotInfo == null || this.dotInfo.range == null) { return null; } Range r = docRange.createRange(); // some xml parsers don't allow end<start in the same text node. So, // handle dot<mark here if (this.markInfo.range.compareBoundaryPoints(Range.START_TO_START, this.dotInfo.range) <= 0) { r.setStart(this.markInfo.range.getStartContainer(), this.markInfo.range.getStartOffset()); r.setEnd(this.dotInfo.range.getStartContainer(), this.dotInfo.range.getStartOffset()); } else { r.setStart(this.dotInfo.range.getStartContainer(), this.dotInfo.range.getStartOffset()); r.setEnd(this.markInfo.range.getStartContainer(), this.markInfo.range.getStartOffset()); } return r; }
protected Node getTarget(){ Node target = null; Range range = getRange(); if (range != null) { target = range.getEndContainer(); } if (target == null) { target = getFocusedNode(); } //if target is still null at this point, check to see if this is a drop to source action. if(target == null){ //if it is, run the drop to source setup and get a valid drop target node back. target = getSelectedNodeFromSource(); } return target; }
/** Not a client function. Called by Range.detach(), * so a Range can remove itself from the list of * Ranges. */ void removeRange(Range range) { if (range == null) return; if (ranges == null) return; removeStaleRangeReferences(); Iterator i = ranges.iterator(); while (i.hasNext()) { Object otherRange = ((Reference) i.next()).get(); if (otherRange == range) { i.remove(); return; } // Remove stale reference from the list. else if (otherRange == null) { i.remove(); } } }
/** Not a client function. Called by Range.detach(), * so a Range can remove itself from the list of * Ranges. */ void removeRange(Range range) { if (range == null) return; if (ranges == null) return; ranges.removeElement(range); }
public Range cloneRange(){ if( fDetach) { throw new DOMException( DOMException.INVALID_STATE_ERR, DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null)); } Range range = fDocument.createRange(); range.setStart(fStartContainer, fStartOffset); range.setEnd(fEndContainer, fEndOffset); return range; }
/** Not a client function. Called by Range.detach(), * so a Range can remove itself from the list of * Ranges. */ void removeRange(Range range) { if (range == null) return; if (ranges == null) return; ranges.remove(range); }
public void selectAll() { if (this.getComponent() == null || this.getComponent().getWidth() == 0 || this.getComponent().getHeight() == 0) { return; } checkDocument(); NodeIterator nodeIterator = this.docTraversal.createNodeIterator(this.document.getDocumentElement(), NodeFilter.SHOW_TEXT, null, false); Text firstText = null; Text lastText = null; while (true) { Node n = nodeIterator.nextNode(); if (n == null) { break; } if (!textInlineMap.containsKey(n)) { continue; } lastText = (Text) n; if (firstText == null) { firstText = lastText; } } if (firstText == null) { return; } Range r = docRange.createRange(); r.setStart(firstText, 0); ViewModelInfo firstPoint = new ViewModelInfo(r, (InlineText) ((List) textInlineMap.get(firstText)).get(0)); r = docRange.createRange(); try { // possibly some dom impls don't handle this? r.setStart(lastText, lastText.getLength()); } catch (Exception e) { r.setStart(lastText, Math.max(0, lastText.getLength() - 1)); } List l = (List) textInlineMap.get(firstText); ViewModelInfo lastPoint = new ViewModelInfo(r, (InlineText) l.get(l.size() - 1)); setDot(firstPoint); moveDot(lastPoint); }
ViewModelInfo(Range range, InlineText text) { this.range = range; this.text = text; }
public String resolve(String infileAddress, String content, String mimeType) throws AddressException{ try{ // get the start and end of the text to find String pieces[] = infileAddress.split("\\.\\.\\."); if(pieces == null || pieces.length != 2){ throw new AddressException("Invalid quote address: " + infileAddress); } String start = pieces[0]; String end = pieces[1]; //System.out.println("start="+start); //System.out.println("end="+end); // parse content into a DOM Document document = parseDocument(content); // now find the beginning and end of the ranges that // match this text Node body = document.getElementsByTagName("body").item(0); Range range = ((DocumentRange)document).createRange(); DocumentTraversal traverse = (DocumentTraversal)document; NodeFilter filter = null; NodeIterator nodes = traverse.createNodeIterator(body, NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_TEXT, filter, true); boolean results = findString(range, START, nodes, start); if(results == false){ throw new AddressException("Unable to find start of quote range: " + start); } // jump the node iterator backwards one; this is for cases // where the start and end text are in the same node nodes.previousNode(); //System.out.println("nodes="+nodes); results = findString(range, END, nodes, end); if(results == false){ throw new AddressException("Unable to find end of quote range: " + end); } // get the fragment represented by this range DocumentFragment fragment = range.cloneContents(); // serialize fragment into string //System.out.println("fragment="+fragment); return serialize((Node)fragment); }catch(Exception e){ e.printStackTrace(); throw new AddressException(e); } }
protected boolean findString(Range range, int rangePos, NodeIterator nodes, String fullString){ return findString(range, rangePos, nodes, fullString, null, null, null); }
/** */ public Range createRange() { if (ranges == null) { ranges = new LinkedList(); rangeReferenceQueue = new ReferenceQueue(); } Range range = new RangeImpl(this); removeStaleRangeReferences(); ranges.add(new WeakReference(range, rangeReferenceQueue)); return range; }
/** */ public Range createRange() { if (ranges == null) { ranges = new ArrayList<>(); } Range range = new RangeImpl(this); ranges.add(range); return range; }
/** */ public Range createRange() { if (ranges == null) { ranges = new Vector(); } Range range = new RangeImpl(this); ranges.addElement(range); return range; }
/** * Gets the range at. * * @param index * the index * @return the range at */ Range getRangeAt(int index);
/** * Adds the range. * * @param range * the range */ void addRange(Range range);
/** * Removes the range. * * @param range * the range */ void removeRange(Range range);