Java Code Examples for com.intellij.psi.xml.XmlDocument#getRootTag()

The following examples show how to use com.intellij.psi.xml.XmlDocument#getRootTag() . 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 File: WeaveEditor.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
private List<String> getGlobalDefinitions(VirtualFile file) {

        List<String> globalDefs = new ArrayList<>();

        final DomManager manager = DomManager.getDomManager(project);
        final XmlFile xmlFile = (XmlFile) PsiManager.getInstance(project).findFile(file);
        final XmlDocument document = xmlFile.getDocument();
        final XmlTag rootTag = document.getRootTag();

        try {
            final XmlTag globalFunctions = rootTag.findFirstSubTag("configuration")
                    .findFirstSubTag("expression-language")
                    .findFirstSubTag("global-functions");
            String nextFunction = globalFunctions.getValue().getText();
            if (nextFunction != null && StringUtils.isNotEmpty(nextFunction)) {
                globalDefs.add(nextFunction);
            }

        } catch (Exception e) {//If the global functions config does not exist, we get NPE - but it's expected :)
            //Do nothing for now
        }
        return globalDefs;
    }
 
Example 2
Source File: SVGParser.java    From svgtoandroid with MIT License 6 votes vote down vote up
public SVGParser(XmlFile svg, String dpi) {
    styles = new HashMap<String, String>();
    this.svg = svg;
    this.dpi = dpi;
    parseDimensions();

    XmlDocument document = svg.getDocument();
    if (document != null) {
        XmlTag rootTag = document.getRootTag();
        if (rootTag != null) {
            XmlTag[] subTags = rootTag.getSubTags();
            for (XmlTag tag : subTags) {
                getChildAttrs(tag);
            }
        }
    }
}
 
Example 3
Source File: Transformer.java    From svgtoandroid with MIT License 5 votes vote down vote up
public void transforming(CallBack callBack) {
    svgParser = new SVGParser(svg, dpi);
    styleParser = new StyleParser(svgParser.getStyles());

    Logger.debug(svgParser.toString());

    XmlFile dist = getDistXml();
    XmlDocument document = dist.getDocument();
    if (document != null && document.getRootTag() != null) {
        XmlTag rootTag = document.getRootTag();

        //set attr to root tag
        try {
            rootTag.getAttribute("android:width").setValue(svgParser.getWidth());
            rootTag.getAttribute("android:height").setValue(svgParser.getHeight());
            rootTag.getAttribute("android:viewportWidth").setValue(svgParser.getViewportWidth());
            rootTag.getAttribute("android:viewportHeight").setValue(svgParser.getViewportHeight());

            if (svgParser.getAlpha().length() > 0) {
                rootTag.setAttribute("android:alpha", svgParser.getAlpha());
            }
        } catch (NullPointerException npe) {
            //do nothing, because those attr is exist certainly.
        }

        //generate group
        if (svgParser.hasGroupTag()) {
            for (XmlTag g : svgParser.getGroups()) {
                parseGroup(g, rootTag);
            }
        } else {
            Logger.warn("Root tag has no subTag named 'group'");
            parseShapeNode(svg.getRootTag(), rootTag, null);
        }
        CodeStyleManager.getInstance(project).reformat(dist, true);
        callBack.onComplete(dist);
        Logger.debug(dist.toString());
    }
}
 
Example 4
Source File: LatteXmlFileInspection.java    From intellij-latte with MIT License 5 votes vote down vote up
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
	if (!(file instanceof XmlFile) || file.getLanguage() != XMLLanguage.INSTANCE || !file.getName().equals(LatteFileConfiguration.FILE_NAME)) {
		return null;
	}

	final List<ProblemDescriptor> problems = new ArrayList<>();

	XmlDocument xmlDocument = ((XmlFile) file).getDocument();
	if (xmlDocument == null) {
		addError(manager, problems, file, "Root tag <latte> is missing", isOnTheFly);
		return problems.toArray(new ProblemDescriptor[0]);
	}

	if (xmlDocument.getRootTag() == null || !xmlDocument.getRootTag().getName().equals("latte")) {
		addError(manager, problems, file, "Root tag <latte> is missing", isOnTheFly);
		return problems.toArray(new ProblemDescriptor[0]);
	}

	XmlTag rootTag = xmlDocument.getRootTag();
	if (rootTag.getAttribute("vendor") == null) {
		PsiElement psiElement = rootTag.getFirstChild().getNextSibling();
		addError(
				manager,
				problems,
				psiElement != null ? psiElement : file,
				"Missing required attribute `vendor` on tag <latte>. It must be unique name like composer package name.",
				isOnTheFly
		);
	}

	return problems.toArray(new ProblemDescriptor[0]);
}
 
Example 5
Source File: LatteXmlFileDataFactory.java    From intellij-latte with MIT License 5 votes vote down vote up
@Nullable
public static LatteXmlFileData parse(XmlFile file) {
    XmlDocument document = file.getDocument();
    if (document == null || document.getRootTag() == null) {
        return null;
    }

    XmlTag configuration = document.getRootTag();
    if (configuration == null) {
        return null;
    }

    LatteXmlFileData.VendorResult vendor = getVendor(document);
    if (vendor == null) {
        return null;
    }

    LatteXmlFileData data = new LatteXmlFileData(vendor);
    XmlTag tags = configuration.findFirstSubTag("tags");
    if (tags != null) {
        loadTags(tags, data);
    }
    XmlTag filters = configuration.findFirstSubTag("filters");
    if (filters != null) {
        loadFilters(filters, data);
    }
    XmlTag variables = configuration.findFirstSubTag("variables");
    if (variables != null) {
        loadVariables(variables, data);
    }
    XmlTag functions = configuration.findFirstSubTag("functions");
    if (functions != null) {
        loadFunctions(functions, data);
    }
    return data;
}
 
Example 6
Source File: LatteXmlFileDataFactory.java    From intellij-latte with MIT License 5 votes vote down vote up
@Nullable
public static LatteXmlFileData.VendorResult getVendor(@Nullable XmlDocument document) {
    if (document == null) {
        return null;
    }
    XmlTag configuration = document.getRootTag();
    if (configuration == null) {
        return null;
    }
    return determineVendor(getTextValue(configuration, "vendor"));
}
 
Example 7
Source File: LatteFileListener.java    From intellij-latte with MIT License 5 votes vote down vote up
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
    for (VFileEvent event : events) {
        VirtualFile file = event.getFile();
        if (!(file instanceof XmlFile) || !file.getName().equals("latte-intellij.xml") || file.isValid()) {
            continue;
        }

        XmlDocument document = ((XmlFile) file).getDocument();
        if (document == null || document.getRootTag() == null) {
            continue;
        }

        LatteXmlFileData.VendorResult vendorResult = LatteXmlFileDataFactory.getVendor(document);
        if (vendorResult == null) {
            continue;
        }

        List<Project> projects = new ArrayList<>();
        Project project = ProjectUtil.guessProjectForContentFile(file);
        if (project != null) {
            projects.add(project);
        } else {
            Collections.addAll(projects, ProjectManager.getInstance().getOpenProjects());
        }

        LatteIndexUtil.notifyRemovedFiles(projects);
    }
}
 
Example 8
Source File: HaxelibUtil.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the list of dependent haxe libraries from an XML-based
 * configuration file.
 *
 * @param psiFile name of the configuration file to read
 * @return a list of dependent libraries; may be empty, won't have duplicates.
 */
@NotNull
public static HaxeLibraryList getHaxelibsFromXmlFile(@NotNull XmlFile psiFile, HaxelibLibraryCache libraryManager) {
  List<HaxeLibraryReference> haxelibNewItems = new ArrayList<HaxeLibraryReference>();

  XmlFile xmlFile = (XmlFile)psiFile;
  XmlDocument document = xmlFile.getDocument();

  if (document != null) {
    XmlTag rootTag = document.getRootTag();
    if (rootTag != null) {
      XmlTag[] haxelibTags = rootTag.findSubTags("haxelib");
      for (XmlTag haxelibTag : haxelibTags) {
        String name = haxelibTag.getAttributeValue("name");
        String ver = haxelibTag.getAttributeValue("version");
        HaxelibSemVer semver = HaxelibSemVer.create(ver);
        if (name != null) {
          HaxeLibrary lib = libraryManager.getLibrary(name, semver);
          if (lib != null) {
            haxelibNewItems.add(lib.createReference(semver));
          } else {
            LOG.warn("Library specified in XML file is not known to haxelib: " + name);
          }
        }
      }
    }
  }

  return new HaxeLibraryList(libraryManager.getSdk(), haxelibNewItems);
}