Java Code Examples for com.intellij.psi.xml.XmlFile#getDocument()

The following examples show how to use com.intellij.psi.xml.XmlFile#getDocument() . 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: MuleSchemaProvider.java    From mule-intellij-plugins with Apache License 2.0 6 votes vote down vote up
@Nullable
private static String getNamespace(final XmlFile xmlFile, final Project project) {
    //Stupid HTTP module XSD weirdo
    if (xmlFile.getName().contains("mule-httpn.xsd"))
        return "http://www.mulesoft.org/schema/mule/http";
    /////

    final XmlDocument document = xmlFile.getDocument();
    if (document != null) {
        final PsiMetaData metaData = document.getMetaData();
        if (metaData instanceof XmlNSDescriptorImpl) {
            return ((XmlNSDescriptorImpl) metaData).getDefaultNamespace();
        }
    }
    return null;
}
 
Example 2
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 3
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 4
Source File: MuleSchemaProvider.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@Override
@NotNull
public Set<String> getAvailableNamespaces(@NotNull XmlFile file, @Nullable String tagName) {
    final Module module = ModuleUtil.findModuleForPsiElement(file);
    Map<String, XmlFile> schemas = getSchemas(module);
    Set<String> namespaces = new HashSet<>();

    try {
        for (XmlFile xsd : schemas.values()) {
            final XmlDocument document = xsd.getDocument();
            if (document != null) {
                final PsiMetaData metaData = document.getMetaData();
                if (metaData instanceof XmlNSDescriptorImpl) {
                    XmlNSDescriptorImpl descriptor = (XmlNSDescriptorImpl) metaData;
                    String defaultNamespace = descriptor.getDefaultNamespace();

                    //Stupid HTTP module XSD weirdo
                    if (xsd.getName().contains("mule-httpn"))
                        defaultNamespace = "http://www.mulesoft.org/schema/mule/http";
                    /////

                    if (StringUtils.isNotEmpty(defaultNamespace)) {
                        if (StringUtils.isNotEmpty(tagName)) {
                            XmlElementDescriptor elementDescriptor = descriptor.getElementDescriptor(tagName, defaultNamespace);
                            if (elementDescriptor != null) {
                                namespaces.add(defaultNamespace);
                            }
                        } else {
                            namespaces.add(defaultNamespace);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        //e.printStackTrace();
    }
    return namespaces;
}
 
Example 5
Source File: MuleSchemaProvider.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
private static boolean isXSD(final XmlFile xmlFile) {
    final XmlDocument document = xmlFile.getDocument();
    if (document != null) {
        final PsiMetaData metaData = document.getMetaData();
        if (metaData instanceof XmlNSDescriptorImpl) {
            return true;
        }
    }
    return false;
}
 
Example 6
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 7
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 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);
}