use of org.jdom.JDOMException in project intellij-plugins by JetBrains.
the class SwcCatalogXmlUtil method parseTimestampsFromCatalogXml.
@SuppressWarnings({ "unchecked" })
private static THashMap<String, TObjectLongHashMap<String>> parseTimestampsFromCatalogXml(@NotNull final VirtualFile catalogFile) {
// <swc xmlns="http://www.adobe.com/flash/swccatalog/9">
// <libraries>
// <library path="library.swf"> take swf name here
// <script name="flash/sampler/StackFrame" mod="1256700285949" signatureChecksum="121164004" > name attribute is not FQN, take only mod here
// <def id="flash.sampler:Sample" /> multiple defs possible
// <def id="flash.sampler:clearSamples" />
// ...
final THashMap<String, TObjectLongHashMap<String>> swfNameToQnameWithTimestampMap = new THashMap<>(1);
try {
final Element rootElement = JDOMUtil.load(catalogFile.getInputStream());
if (rootElement != null && "swc".equals(rootElement.getName())) {
for (final Element librariesElement : rootElement.getChildren("libraries", rootElement.getNamespace())) {
for (final Element libraryElement : librariesElement.getChildren("library", librariesElement.getNamespace())) {
final String swfName = libraryElement.getAttributeValue("path");
if (StringUtil.isEmpty(swfName)) {
continue;
}
final TObjectLongHashMap<String> qNameWithTimestampMap = new TObjectLongHashMap<>();
swfNameToQnameWithTimestampMap.put(swfName, qNameWithTimestampMap);
for (final Element scriptElement : libraryElement.getChildren("script", libraryElement.getNamespace())) {
final String mod = scriptElement.getAttributeValue("mod");
if (StringUtil.isEmpty(mod)) {
continue;
}
try {
final long timestamp = Long.parseLong(mod);
for (final Element defElement : scriptElement.getChildren("def", scriptElement.getNamespace())) {
final String id = defElement.getAttributeValue("id");
if (!StringUtil.isEmpty(id)) {
final String fqn = id.replace(':', '.');
qNameWithTimestampMap.put(fqn, timestamp);
}
}
} catch (NumberFormatException ignored) {
/*ignore*/
}
}
}
}
}
} catch (JDOMException ignored) {
/*ignore*/
} catch (IOException ignored) {
/*ignore*/
}
return swfNameToQnameWithTimestampMap;
}
use of org.jdom.JDOMException in project intellij-plugins by JetBrains.
the class P2PNetworkXmlMessage method processResponse.
void processResponse() {
if (myMessage == null || !myMessage.needsResponse())
return;
try {
final String response = getResponse().toString();
if (!com.intellij.openapi.util.text.StringUtil.isEmptyOrSpaces(response)) {
Document document = new SAXBuilder().build(new StringReader(response));
myMessage.processResponse(document.getRootElement());
}
} catch (JDOMException e) {
LOG.error(e.getMessage(), e);
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}
}
use of org.jdom.JDOMException in project intellij-plugins by JetBrains.
the class FlexCommonUtils method findXMLElement.
@Nullable
public static String findXMLElement(final InputStream is, final String xmlElement) {
// xmlElement has format "<root_tag><child_tag>"
final List<String> elementNames = StringUtil.split(StringUtil.replace(xmlElement, ">", ""), "<");
if (elementNames.isEmpty())
return null;
try {
final Element root = JDOMUtil.load(is);
if (!root.getName().equals(elementNames.get(0))) {
return null;
}
Element element = root;
int depth = 0;
while (elementNames.size() > ++depth) {
element = element.getChild(elementNames.get(depth), element.getNamespace());
if (element == null) {
return null;
}
}
return element.getTextNormalize();
} catch (JDOMException | IOException ignore) {
/**/
}
return null;
}
use of org.jdom.JDOMException in project intellij-plugins by JetBrains.
the class InfoFromConfigFile method getInfoFromConfigFile.
@NotNull
public static InfoFromConfigFile getInfoFromConfigFile(final String configFilePath) {
final File configFile = configFilePath.isEmpty() ? null : new File(configFilePath);
if (configFile == null || !configFile.isFile()) {
ourCache.remove(configFilePath);
return DEFAULT;
}
String canonicalPath;
try {
canonicalPath = configFile.getCanonicalPath();
} catch (IOException e) {
canonicalPath = configFile.getPath();
}
Pair<Long, InfoFromConfigFile> data = ourCache.get(canonicalPath);
final Long currentTimestamp = configFile.lastModified();
final Long cachedTimestamp = data == null ? null : data.first;
if (cachedTimestamp == null || !cachedTimestamp.equals(currentTimestamp)) {
ourCache.remove(canonicalPath);
String mainClassPath = null;
String outputPath = null;
String targetPlayer = null;
try {
final Element rootElement = JDOMUtil.load(configFile);
final Element fileSpecsElement = rootElement.getChild("file-specs", rootElement.getNamespace());
mainClassPath = fileSpecsElement == null ? null : fileSpecsElement.getChildTextNormalize("path-element", rootElement.getNamespace());
outputPath = rootElement.getChildTextNormalize("output", rootElement.getNamespace());
if (outputPath != null && !FileUtil.isAbsolute(outputPath)) {
try {
outputPath = FileUtil.toSystemIndependentName(new File(configFile.getParent(), outputPath).getCanonicalPath());
} catch (IOException e) {
outputPath = FileUtil.toSystemIndependentName(new File(configFile.getParent(), outputPath).getAbsolutePath());
}
}
targetPlayer = rootElement.getChildTextNormalize("target-player", rootElement.getNamespace());
} catch (IOException | JDOMException ignore) {
/*ignore*/
}
final String outputFileName = outputPath == null ? null : PathUtilRt.getFileName(outputPath);
final String outputFolderPath = outputPath == null ? null : PathUtilRt.getParentPath(outputPath);
data = Pair.create(currentTimestamp, new InfoFromConfigFile(configFile, mainClassPath, outputFileName, outputFolderPath, targetPlayer));
ourCache.put(canonicalPath, data);
}
return data.second;
}
use of org.jdom.JDOMException in project intellij-plugins by JetBrains.
the class FlexCommonUtils method parseAirVersionFromDescriptorFile.
@Nullable
public static String parseAirVersionFromDescriptorFile(final String descriptorFilePath) {
if (StringUtil.isEmpty(descriptorFilePath))
return null;
try {
final Element rootElement = JDOMUtil.load(new File(descriptorFilePath));
final String localName = rootElement.getName();
final Namespace namespace = rootElement.getNamespace();
if ("application".equals(localName) && namespace != null && namespace.getURI().startsWith(AIR_NAMESPACE_BASE)) {
return namespace.getURI().substring(AIR_NAMESPACE_BASE.length());
}
} catch (JDOMException | IOException e) {
/*unlucky*/
}
return null;
}
Aggregations