Java Code Examples for com.intellij.util.xml.DomFileElement

The following examples show how to use com.intellij.util.xml.DomFileElement. 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: mule-intellij-plugins   Source File: MuleConfigUtils.java    License: Apache License 2.0 6 votes vote down vote up
@NotNull
private static List<DomElement> getFlowsInScope(Project project, GlobalSearchScope searchScope) {
    final List<DomElement> result = new ArrayList<>();
    final Collection<VirtualFile> files = FileTypeIndex.getFiles(StdFileTypes.XML, searchScope);
    final DomManager manager = DomManager.getDomManager(project);
    for (VirtualFile file : files) {
        final PsiFile xmlFile = PsiManager.getInstance(project).findFile(file);
        if (isMuleFile(xmlFile)) {
            final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class);
            if (fileElement != null) {
                final Mule rootElement = fileElement.getRootElement();
                result.addAll(rootElement.getFlows());
                result.addAll(rootElement.getSubFlows());
            }
        }
    }
    return result;
}
 
Example 2
Source Project: mule-intellij-plugins   Source File: MuleConfigUtils.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private static XmlTag findGlobalElementInFile(Project project, String elementName, VirtualFile file) {
    final DomManager manager = DomManager.getDomManager(project);
    final PsiFile xmlFile = PsiManager.getInstance(project).findFile(file);
    if (isMuleFile(xmlFile)) {
        final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class);
        if (fileElement != null) {
            final Mule rootElement = fileElement.getRootElement();
            final XmlTag[] subTags = rootElement.getXmlTag().getSubTags();
            for (XmlTag subTag : subTags) {
                if (isGlobalElement(subTag)) {
                    if (elementName.equals(subTag.getAttributeValue(MuleConfigConstants.NAME_ATTRIBUTE))) {
                        return subTag;
                    }
                }
            }
        }
    }
    return null;
}
 
Example 3
Source Project: mule-intellij-plugins   Source File: MuleConfigUtils.java    License: Apache License 2.0 6 votes vote down vote up
@Nullable
private static XmlTag findFlowInFile(Project project, String flowName, VirtualFile file) {
    final DomManager manager = DomManager.getDomManager(project);
    final PsiFile xmlFile = PsiManager.getInstance(project).findFile(file);
    if (isMuleFile(xmlFile)) {
        final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class);
        if (fileElement != null) {
            final Mule rootElement = fileElement.getRootElement();
            final List<Flow> flows = rootElement.getFlows();
            for (Flow flow : flows) {
                if (flowName.equals(flow.getName().getValue())) {
                    return flow.getXmlTag();
                }
            }
            final List<SubFlow> subFlows = rootElement.getSubFlows();
            for (SubFlow subFlow : subFlows) {
                if (flowName.equals(subFlow.getName().getValue())) {
                    return subFlow.getXmlTag();
                }
            }
        }
    }
    return null;
}
 
Example 4
Source Project: mule-intellij-plugins   Source File: MuleConfigUtils.java    License: Apache License 2.0 6 votes vote down vote up
@NotNull
private static List<XmlTag> getGlobalElementsInScope(Project project, GlobalSearchScope searchScope) {
    final List<XmlTag> result = new ArrayList<>();
    final Collection<VirtualFile> files = FileTypeIndex.getFiles(StdFileTypes.XML, searchScope);
    final DomManager manager = DomManager.getDomManager(project);
    for (VirtualFile file : files) {
        final PsiFile xmlFile = PsiManager.getInstance(project).findFile(file);
        if (isMuleFile(xmlFile)) {
            final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class);
            if (fileElement != null) {
                final Mule rootElement = fileElement.getRootElement();
                final XmlTag[] subTags = rootElement.getXmlTag().getSubTags();
                for (XmlTag subTag : subTags) {
                    if (isGlobalElement(subTag)) {
                        result.add(subTag);
                    }
                }
            }
        }
    }
    return result;
}
 
Example 5
@Override
protected SimpleNode[] buildChildren() {
    List<SimpleNode> myConfigNodes = new ArrayList<>();

    final DomManager manager = DomManager.getDomManager(myProject);
    final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) myXmlFile, Mule.class);

    if (fileElement != null) {
        final Mule rootElement = fileElement.getRootElement();
        XmlTag[] subTags = rootElement.getXmlTag().getSubTags();

        for (XmlTag nextTag : subTags) {
            MuleElementType muleElementType = MuleConfigUtils.getMuleElementTypeFromXmlElement(nextTag);

            if (muleElementType != null && //This is a global config
                    (MuleElementType.CONFIG.equals(muleElementType) || (MuleElementType.TRANSPORT_CONNECTOR.equals(muleElementType)))) {

                GlobalConfigNode nextConfigNode = new GlobalConfigNode(this, nextTag);
                myConfigNodes.add(nextConfigNode);
            }
        }
    }
    return myConfigNodes.toArray(new SimpleNode[]{});
}
 
Example 6
@Override
        protected SimpleNode[] buildChildren() {
            List<SimpleNode> myConfigNodes = new ArrayList<>();

            final DomManager manager = DomManager.getDomManager(myProject);

            final Collection<VirtualFile> files = FileTypeIndex.getFiles(StdFileTypes.XML, GlobalSearchScope.projectScope(myProject));

            for (VirtualFile file : files) {

                final PsiFile xmlFile = PsiManager.getInstance(myProject).findFile(file);

                if (xmlFile != null) {
//                    PsiDirectory directory = xmlFile.getParent();
//                    Module module = ModuleUtilCore.findModuleForPsiElement((PsiElement) (directory == null ? xmlFile : directory));

                    if (MuleConfigUtils.isMuleFile(xmlFile)) {
                        final DomFileElement<Mule> fileElement = manager.getFileElement((XmlFile) xmlFile, Mule.class);

                        if (fileElement != null) {
                            final Mule rootElement = fileElement.getRootElement();
                            XmlTag[] subTags = rootElement.getXmlTag().getSubTags();

                            for (XmlTag nextTag : subTags) {
                                MuleElementType muleElementType = MuleConfigUtils.getMuleElementTypeFromXmlElement(nextTag);

                                if (muleElementType != null && //This is a global config file and it has at least one connector
                                        (MuleElementType.CONFIG.equals(muleElementType) || (MuleElementType.TRANSPORT_CONNECTOR.equals(muleElementType)))) {
                                    MuleConfigNode nextConfigNode = new MuleConfigNode(this, xmlFile);
                                    myConfigNodes.add(nextConfigNode);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return myConfigNodes.toArray(new SimpleNode[]{});
        }
 
Example 7
@Nullable
private static <T> T getRootElement(final PsiFile file, final Class<T> domClass, final Module module) {
    if(!(file instanceof XmlFile)) return null;
    final DomManager domManager = DomManager.getDomManager(file.getProject());
    final DomFileElement<DomElement> element = domManager.getFileElement((XmlFile) file, DomElement.class);
    if(element == null) return null;
    final DomElement root = element.getRootElement();
    if(!ReflectionUtil.isAssignable(domClass, root.getClass())) return null;
    return (T) root;
}
 
Example 8
Source Project: MavenHelper   Source File: RemoveDependencyAction.java    License: Apache License 2.0 5 votes vote down vote up
private void exclude() {
	DomFileElement domFileElement = getDomFileElement(myArtifact);

	if (domFileElement != null) {
		final MavenDomProjectModel rootElement = (MavenDomProjectModel) domFileElement.getRootElement();
		final MavenDomDependencies dependencies = rootElement.getDependencies();
		boolean found = false;

		for (MavenDomDependency mavenDomDependency : dependencies.getDependencies()) {
			if (isSameDependency(myArtifact.getArtifact(), mavenDomDependency)) {
				found = true;
				mavenDomDependency.undefine();
				dependencyDeleted();
			}
		}
		if (!found) {
			final Notification notification = new Notification(MAVEN_HELPER_DEPENDENCY_ANALYZER_NOTIFICATION, "",
					"Parent dependency not found, it is probably in the parent pom", NotificationType.WARNING);
			ApplicationManager.getApplication().invokeLater(new Runnable() {
				@Override
				public void run() {
					Notifications.Bus.notify(notification, myProject);
				}
			});
		}
	}
}
 
Example 9
Source Project: MavenHelper   Source File: BaseAction.java    License: Apache License 2.0 5 votes vote down vote up
protected DomFileElement getDomFileElement(MavenArtifactNode mavenArtifactNode) {
		XmlFile xmlFile = getXmlFile(mavenArtifactNode);
		if (xmlFile == null) {
//			showError(mavenArtifactNode);
			return null;
		}
		DomFileElement<MavenDomProjectModel> fileElement = DomManager.getDomManager(myProject).getFileElement(xmlFile, MavenDomProjectModel.class);

		if (fileElement == null) {
			showError(xmlFile);
		}
		return fileElement;
	}
 
Example 10
Source Project: MavenHelper   Source File: ExcludeDependencyAction.java    License: Apache License 2.0 5 votes vote down vote up
private void exclude() {
	final MavenArtifact artifactToExclude = myArtifact.getArtifact();
	final MavenArtifactNode oldestParent = getOldestParentMavenArtifact();

	DomFileElement domFileElement = getDomFileElement(oldestParent);

	if (domFileElement != null) {
		final MavenDomProjectModel rootElement = (MavenDomProjectModel) domFileElement.getRootElement();
		final MavenDomDependencies dependencies = rootElement.getDependencies();
		boolean found = false;

		for (MavenDomDependency mavenDomDependency : dependencies.getDependencies()) {
			if (isSameDependency(oldestParent.getArtifact(), mavenDomDependency)) {
				found = true;
				final MavenDomExclusions exclusions = mavenDomDependency.getExclusions();
				for (MavenDomExclusion mavenDomExclusion : exclusions.getExclusions()) {
					if (isSameDependency(artifactToExclude, mavenDomExclusion)) {
						return;
					}
				}
				createExclusion(artifactToExclude, exclusions);
				dependencyExcluded();
			}
		}
		if (!found) {
			final Notification notification = new Notification(MAVEN_HELPER_DEPENDENCY_ANALYZER_NOTIFICATION, "",
					"Parent dependency not found, it is probably in the parent pom", NotificationType.WARNING);
			ApplicationManager.getApplication().invokeLater(new Runnable() {
				@Override
				public void run() {
					Notifications.Bus.notify(notification, myProject);
				}
			});
		}
	}
}