public ReplaceEdit createReplaceFolderEdit(IFolder originalFolder, String newName) { IDOMNode domNode = getTextNode(); String originalName = originalFolder.getName(); int nameIndex = this.fileName.indexOf(originalName); int offset = domNode.getStartOffset(); return new ReplaceEdit(offset + nameIndex, originalName.length(), newName); }
/** * Returns the CMDocument that corresponds to the DOM Node. or null if no CMDocument is * appropriate for the DOM Node. */ public CMDocument getCorrespondingCMDocument(Node node) { CMDocument jcmdoc = null; if (node instanceof IDOMNode) { IDOMModel model = ((IDOMNode) node).getModel(); String modelPath = model.getBaseLocation(); if (modelPath != null && !IModelManager.UNMANAGED_MODEL.equals(modelPath)) { float version = DeploymentDescriptorPropertyCache.getInstance().getJSPVersion(new Path(modelPath)); jcmdoc = JSPCMDocumentFactory.getCMDocument(version); } } if (jcmdoc == null) { jcmdoc = JSPCMDocumentFactory.getCMDocument(); } CMDocument result = null; try { if (node.getNodeType() == Node.ELEMENT_NODE) { String elementName = node.getNodeName(); // test to see if this node belongs to JSP's CMDocument (case // sensitive) CMElementDeclaration dec = (CMElementDeclaration) jcmdoc.getElements().getNamedItem(elementName); if (dec != null) { result = jcmdoc; } } String prefix = node.getPrefix(); if (result == null && prefix != null && prefix.length() > 0 && node instanceof IDOMNode) { // check position dependent IDOMNode xmlNode = (IDOMNode) node; TLDCMDocumentManager tldmgr = TaglibController.getTLDCMDocumentManager(xmlNode.getStructuredDocument()); if (tldmgr != null) { List documents = tldmgr.getCMDocumentTrackers(node.getPrefix(), xmlNode.getStartOffset()); // there shouldn't be more than one cmdocument returned if (documents != null && documents.size() > 0) result = (CMDocument) documents.get(0); } } } catch (Exception e) { e.printStackTrace(); } return result; }
protected int getOffset(ITextRegion valueRegion, IDOMNode beanNode) { return valueRegion.getStart() + beanNode.getStartOffset() + 1; }