下面列出了com.intellij.psi.xml.XmlFile#getDocument ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
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;
}
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);
}
}
}
}
@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;
}
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;
}
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());
}
}
@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;
}
/**
* 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);
}