use of org.jdom.JDOMException in project intellij-plugins by JetBrains.
the class FlexCompilerConfigFileUtilBase method mergeWithCustomConfigFile.
public static String mergeWithCustomConfigFile(final String generatedConfigText, final String additionalConfigFilePath, final boolean makeExternalLibsMerged, final boolean makeIncludedLibsMerged) {
final File additionalConfigFile = new File(additionalConfigFilePath);
if (!additionalConfigFile.isFile()) {
return generatedConfigText;
}
final Element rootElement;
try {
rootElement = JDOMUtil.load(additionalConfigFile);
} catch (JDOMException | IOException e) {
return generatedConfigText;
}
if (!FLEX_CONFIG.equals(rootElement.getName())) {
return generatedConfigText;
}
removeSwcSpecificElementsRecursively(rootElement);
makeLibrariesMergedIntoCode(rootElement, makeExternalLibsMerged, makeIncludedLibsMerged);
try {
final Element otherRootElement = JDOMUtil.load(generatedConfigText);
assert FLEX_CONFIG.equals(rootElement.getName()) : JDOMUtil.writeElement(rootElement);
appendDocument(rootElement, otherRootElement);
} catch (IOException | JDOMException e) {
assert false : e.getMessage() + "\n" + generatedConfigText;
}
return JDOMUtil.writeElement(rootElement);
}
use of org.jdom.JDOMException in project intellij-plugins by JetBrains.
the class FlexBuilderUtils method fixInitialContent.
private static String fixInitialContent(final File descriptorFile, final String swfName) throws IOException, JDOMException {
// hardcoded UTF-8 makes it work the same way as it worked in FlexCompilationUtils.fixInitialContent() for ages (UTF-8 is hardcoded in JDOMUtil)
final String descriptorContent = FileUtil.loadFile(descriptorFile, "UTF-8");
final Element rootElement = JDOMUtil.load(StringUtil.trimStart(descriptorContent, ""));
if (!"application".equals(rootElement.getName())) {
throw new JDOMException("incorrect root tag");
}
Element initialWindowElement = rootElement.getChild("initialWindow", rootElement.getNamespace());
if (initialWindowElement == null) {
initialWindowElement = new Element("initialWindow", rootElement.getNamespace());
rootElement.addContent(initialWindowElement);
}
Element contentElement = initialWindowElement.getChild("content", rootElement.getNamespace());
if (contentElement == null) {
contentElement = new Element("content", rootElement.getNamespace());
initialWindowElement.addContent(contentElement);
}
contentElement.setText(swfName);
return JDOMUtil.write(rootElement, SystemProperties.getLineSeparator());
}
use of org.jdom.JDOMException in project intellij-plugins by JetBrains.
the class FlexBuilderUtils method replaceMacros.
private static String replaceMacros(final String wrapperText, final String outputFileName, final String targetPlayer, final String mainClassPath) {
final Map<String, String> replacementMap = new THashMap<>();
replacementMap.put(FlexCommonUtils.SWF_MACRO, outputFileName);
replacementMap.put(FlexCommonUtils.TITLE_MACRO, outputFileName);
replacementMap.put(FlexCommonUtils.APPLICATION_MACRO, outputFileName);
replacementMap.put(FlexCommonUtils.BG_COLOR_MACRO, "#ffffff");
replacementMap.put(FlexCommonUtils.WIDTH_MACRO, "100%");
replacementMap.put(FlexCommonUtils.HEIGHT_MACRO, "100%");
final List<String> versionParts = StringUtil.split(targetPlayer, ".");
replacementMap.put(FlexCommonUtils.VERSION_MAJOR_MACRO, versionParts.size() >= 1 ? versionParts.get(0) : "0");
replacementMap.put(FlexCommonUtils.VERSION_MINOR_MACRO, versionParts.size() >= 2 ? versionParts.get(1) : "0");
replacementMap.put(FlexCommonUtils.VERSION_REVISION_MACRO, versionParts.size() >= 3 ? versionParts.get(2) : "0");
String swfMetadata = null;
final File mainClassFile = new File(mainClassPath);
if (mainClassFile.isFile()) {
try {
if (FileUtilRt.extensionEquals(mainClassPath, "mxml")) {
final Element rootElement = JDOMUtil.load(mainClassFile);
Element metadataElement = rootElement.getChild("Metadata", Namespace.getNamespace("http://www.adobe.com/2006/mxml"));
if (metadataElement == null) {
metadataElement = rootElement.getChild("Metadata", Namespace.getNamespace("http://ns.adobe.com/mxml/2009"));
}
if (metadataElement != null) {
swfMetadata = getSwfMetadata(metadataElement.getTextNormalize());
}
} else if (FileUtilRt.extensionEquals(mainClassPath, "as")) {
swfMetadata = getSwfMetadata(FileUtil.loadFile(mainClassFile));
}
} catch (JDOMException | IOException ignore) {
/*unlucky*/
}
}
final Map<String, String> attributesMap = getAttributesMap(swfMetadata);
ContainerUtil.putIfNotNull(FlexCommonUtils.TITLE_MACRO, attributesMap.get(FlexCommonUtils.TITLE_ATTR), replacementMap);
ContainerUtil.putIfNotNull(FlexCommonUtils.BG_COLOR_MACRO, attributesMap.get(FlexCommonUtils.BG_COLOR_ATTR), replacementMap);
ContainerUtil.putIfNotNull(FlexCommonUtils.WIDTH_MACRO, attributesMap.get(FlexCommonUtils.WIDTH_ATTR), replacementMap);
ContainerUtil.putIfNotNull(FlexCommonUtils.HEIGHT_MACRO, attributesMap.get(FlexCommonUtils.HEIGHT_ATTR), replacementMap);
return FlexCommonUtils.replace(wrapperText, replacementMap);
}
use of org.jdom.JDOMException in project intellij-plugins by JetBrains.
the class FlashBuilderSdkFinder method loadSdkInfoDocument.
@Nullable
private static Element loadSdkInfoDocument(final String flashBuilderWorkspacePath) {
try {
final VirtualFile projectPrefsFile = LocalFileSystem.getInstance().findFileByPath(flashBuilderWorkspacePath + FlashBuilderProjectFinder.PROJECT_PREFS_RELATIVE_PATH);
if (projectPrefsFile == null)
return null;
final Properties projectPrefsProperties = new Properties();
projectPrefsProperties.load(projectPrefsFile.getInputStream());
final String xmlString = projectPrefsProperties.getProperty(FLEX_SDK_PROPERTY);
if (xmlString == null)
return null;
return JDOMUtil.load(xmlString);
} catch (IOException e) {
/*ignore*/
} catch (JDOMException e) {
/*ignore*/
}
return null;
}
use of org.jdom.JDOMException in project intellij-plugins by JetBrains.
the class FlashBuilderProjectLoadUtil method loadInfoFromDotFlexLibPropertiesFile.
private static void loadInfoFromDotFlexLibPropertiesFile(final FlashBuilderProject project, final VirtualFile dotProjectFile) {
final VirtualFile dotFlexLibPropertiesFile = dotProjectFile.getParent().findChild(FlashBuilderImporter.DOT_FLEX_LIB_PROPERTIES);
if (dotFlexLibPropertiesFile != null) {
try {
final Element flexLibPropertiesElement = JDOMUtil.load(dotFlexLibPropertiesFile.getInputStream());
if (!FLEX_LIB_PROPERTIES_TAG.equals(flexLibPropertiesElement.getName()))
return;
if (project.getTargetPlatform() == TargetPlatform.Desktop && "true".equals(flexLibPropertiesElement.getAttributeValue(USE_MULTIPLATFORM_CONFIG_ATTR))) {
project.setTargetPlatform(TargetPlatform.Mobile);
}
//noinspection unchecked
for (final Element namespaceManifestsElement : flexLibPropertiesElement.getChildren(NAMESPACE_MANIFESTS_TAG, flexLibPropertiesElement.getNamespace())) {
//noinspection unchecked
for (final Element namespaceManifestEntryElement : namespaceManifestsElement.getChildren(NAMESPACE_MANIFEST_ENTRY_TAG, namespaceManifestsElement.getNamespace())) {
final String namespace = namespaceManifestEntryElement.getAttributeValue(NAMESPACE_ATTR);
final String manifestPath = namespaceManifestEntryElement.getAttributeValue(MANIFEST_ATTR);
if (!StringUtil.isEmpty(manifestPath) && !StringUtil.isEmpty(namespace)) {
project.addNamespaceAndManifestPath(namespace, FileUtil.toSystemIndependentName(manifestPath));
}
}
}
//noinspection unchecked
for (final Element includeResourcesElement : flexLibPropertiesElement.getChildren(INCLUDE_RESOURCES_ELEMENT, flexLibPropertiesElement.getNamespace())) {
//noinspection unchecked
for (final Element resourceEntryElement : includeResourcesElement.getChildren(RESOURCE_ENTRY_ELEMENT, includeResourcesElement.getNamespace())) {
final String sourcePath = resourceEntryElement.getAttributeValue(SOURCE_PATH_ATTR);
if (!StringUtil.isEmpty(sourcePath)) {
project.addFileIncludedInSwc(FileUtil.toSystemIndependentName(sourcePath));
}
}
}
} catch (JDOMException ignored) {
/*ignore*/
} catch (IOException ignored) {
/*ignore*/
}
}
}
Aggregations