public String getAttributeValue(String _name, String namespace) { if (namespace == null) { return getAttributeValue(_name); } XmlTagImpl current = this; PsiElement parent = getParent(); while (current != null) { BidirectionalMap<String, String> map = current.initNamespaceMaps(parent); if (map != null) { List<String> keysByValue = map.getKeysByValue(namespace); if (keysByValue != null && !keysByValue.isEmpty()) { for (String prefix : keysByValue) { if (prefix != null && prefix.length() > 0) { final String value = getAttributeValue(prefix + ":" + _name); if (value != null) return value; } } } } current = parent instanceof XmlTag ? (XmlTagImpl) parent : null; parent = parent.getParent(); } if (namespace.length() == 0 || getNamespace().equals(namespace)) { return getAttributeValue(_name); } return null; }
@Nullable private static String getNSVersion(String ns, final XmlTagImpl xmlTag) { String versionValue = xmlTag.getAttributeValue("version"); if (versionValue != null && xmlTag.getNamespace().equals(ns)) { return versionValue; } return null; }
public PomModelEvent runInner() throws IncorrectOperationException { final ASTNode anchor = expandTag(); if (myChild.getElementType() == XmlElementType.XML_TAG) { // compute where to insert tag according to DTD or XSD final XmlElementDescriptor parentDescriptor = getDescriptor(); final XmlTag[] subTags = getSubTags(); final PsiElement declaration = parentDescriptor != null ? parentDescriptor.getDeclaration() : null; // filtring out generated dtds if (declaration != null && declaration.getContainingFile() != null && declaration.getContainingFile().isPhysical() && subTags.length > 0) { final XmlElementDescriptor[] childElementDescriptors = parentDescriptor.getElementsDescriptors(XmlTagImpl.this); int subTagNum = -1; for (final XmlElementDescriptor childElementDescriptor : childElementDescriptors) { final String childElementName = childElementDescriptor.getName(); while (subTagNum < subTags.length - 1 && subTags[subTagNum + 1].getName().equals(childElementName)) { subTagNum++; } if (childElementName.equals( XmlChildRole.START_TAG_NAME_FINDER.findChild(myChild).getText())) { // insert child just after anchor // insert into the position specified by index if (subTagNum >= 0) { final ASTNode subTag = (ASTNode) subTags[subTagNum]; if (subTag.getTreeParent() != XmlTagImpl.this) { // in entity final XmlEntityRef entityRef = PsiTreeUtil.getParentOfType(subTags[subTagNum], XmlEntityRef.class); throw new IncorrectOperationException( "Can't insert subtag to the entity. Entity reference text: " + (entityRef == null ? "" : entityRef.getText())); } myNewElement = XmlTagImpl.super.addInternal(myChild, myChild, subTag, Boolean.FALSE); } else { final ASTNode child = XmlChildRole.START_TAG_END_FINDER.findChild(XmlTagImpl.this); myNewElement = XmlTagImpl.super.addInternal(myChild, myChild, child, Boolean.FALSE); } return null; } } } else { final ASTNode child = XmlChildRole.CLOSING_TAG_START_FINDER.findChild(XmlTagImpl.this); myNewElement = XmlTagImpl.super.addInternal(myChild, myChild, child, Boolean.TRUE); return null; } } myNewElement = XmlTagImpl.super.addInternal(myChild, myChild, anchor, Boolean.TRUE); return null; }
public PomModelEvent runInner() { final String value = ((XmlAttribute) myChild).getValue(); final String name = ((XmlAttribute) myChild).getName(); if (myAnchor == null) { ASTNode startTagEnd = XmlChildRole.START_TAG_END_FINDER.findChild(XmlTagImpl.this); if (startTagEnd == null) startTagEnd = XmlChildRole.EMPTY_TAG_END_FINDER.findChild(XmlTagImpl.this); if (startTagEnd == null) { ASTNode anchor = getLastChildNode(); while (anchor instanceof PsiWhiteSpace) { anchor = anchor.getTreePrev(); } if (anchor instanceof PsiErrorElement) { final LeafElement token = Factory.createSingleLeafElement( XmlTokenType.XML_EMPTY_ELEMENT_END, "/>", 0, 2, SharedImplUtil.findCharTableByTree(anchor), getManager()); replaceChild(anchor, token); startTagEnd = token; } } if (startTagEnd == null) { ASTNode anchor = XmlChildRole.START_TAG_NAME_FINDER.findChild(XmlTagImpl.this); myFirstInserted = XmlTagImpl.super.addInternal(myChild, myChild, anchor, Boolean.FALSE); } else { myFirstInserted = XmlTagImpl.super.addInternal(myChild, myChild, startTagEnd, Boolean.TRUE); } } else { myFirstInserted = XmlTagImpl.super.addInternal(myChild, myChild, myAnchor, Boolean.valueOf(myBefore)); } return XmlAttributeSetImpl.createXmlAttributeSet(myModel, XmlTagImpl.this, name, value); }
public void deleteChildInternal(@NotNull final ASTNode child) { final PomModel model = PomManager.getModel(getProject()); final XmlAspect aspect = model.getModelAspect(XmlAspect.class); if (child.getElementType() == XmlElementType.XML_ATTRIBUTE) { try { model.runTransaction( new PomTransactionBase(this, aspect) { public PomModelEvent runInner() { final String name = ((XmlAttribute) child).getName(); XmlTagImpl.super.deleteChildInternal(child); return XmlAttributeSetImpl.createXmlAttributeSet( model, XmlTagImpl.this, name, null); } }); } catch (IncorrectOperationException e) { LOG.error(e); } } else { final ASTNode treePrev = child.getTreePrev(); final ASTNode treeNext = child.getTreeNext(); XmlTagImpl.super.deleteChildInternal(child); if (treePrev != null && treeNext != null && treePrev.getElementType() == XmlElementType.XML_TEXT && treeNext.getElementType() == XmlElementType.XML_TEXT) { final XmlText prevText = (XmlText) treePrev.getPsi(); final XmlText nextText = (XmlText) treeNext.getPsi(); try { prevText.setValue(prevText.getValue() + nextText.getValue()); nextText.delete(); } catch (IncorrectOperationException e) { LOG.error(e); } } } }
public PomModelEvent runInner() { myRetHolder = XmlTagImpl.super.addInternal(myChild, myChild, myAnchor, Boolean.valueOf(myBefore)); return null; }