Issues with Adobe AIR File access when file name has a semi-colon - macos

I have a piece of code in AIR that accesses a file on the hard drive. This fails to work on a mac if the file name contains a semi-colon. It throws an exception that it can't find the file. If I rename the file and remove the semi-colon and point to it it works fine so the code is ok. The only problem is when the filename contains a semi-colon. The exception occurs on the line where I request file.size.
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="windowedapplication1_creationCompleteHandler(event)">
<fx:Script> <![CDATA[
import mx.events.FlexEvent;
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
var f:File = new File("file:///Users/foo/pix/test;1.JPG");
trace (" here" + f.size );
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:WindowedApplication>

Don't use semi colons in filenames.
See this article from 2007
http://www.portfoliofaq.com/pfaq/FAQ00352.htm
Deprecated filename characters (; and ,). (All OSs).

Related

How to edit vsixmanifest using groovy without loosing content?

My question may sound stupid but I am struggling to achieve my result. I would like to edit and save version tage of vsixmanifest file without loosing any content. This article almost solved my purpose but it removes some of the tags.
<?xml version="1.0" encoding="utf-8"?>
<Vsix xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010">
<Identifier Id="Visual Test">
<Name>Visual Gallery Test</Name>
<Author>Visual Studio Demo</Author>
<Version>XXXXX</Version>
<Description xml:space="preserve">Visual Studio Gallery Demo</Description>
<Locale>1033</Locale>
<AllUsers>true</AllUsers>
<InstalledByMsi>false</InstalledByMsi>
<Icon>Resources/Icon.png</Icon>
<PreviewImage>Resources/Preview.png</PreviewImage>
<SupportedProducts>
<IsolatedShell Version="7.0">Visual Studio</IsolatedShell>
</SupportedProducts>
<SupportedFrameworkRuntimeEdition MinVersion="4.6" MaxVersion="4.9" />
</Identifier>
<Content>
<VsPackage>XX.pkgdef</VsPackage>
</Content>
</Vsix>
Here is my gradle script
task updateExtensionManifest{
def vsixmanifestFile = "build/source.extension.vsixmanifest"
def vsixmanifest = new XmlParser().parse(vsixmanifestFile)
vsixmanifest.Identifier[0].Version[0].value="YYYYY"
def nodePrinter = new XmlNodePrinter(new PrintWriter(new FileWriter(vsixmanifestFile)))
nodePrinter.preserveWhitespace = true
nodePrinter.expandEmptyElements = true
nodePrinter.print(vsixmanifest)
}
When I execute the script it removes some of the tags defines manifest file, this is how it looks after task is getting executed:
<Vsix xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010" Version="1.0.0">
<Identifier Id="Visual Test">
<Name>Visual Gallery Test</Name>
<Author>Visual Studio Demo</Author>
<Version>YYYYY</Version>
<Description xml:space="preserve" xmlns:xml="http://www.w3.org/XML/1998/namespace">Visual Studio Gallery Demo</Description>
<Locale>1033</Locale>
<AllUsers>true</AllUsers>
<InstalledByMsi>false</InstalledByMsi>
<Icon>Resources/Icon.png</Icon>
<PreviewImage>Resources/Preview.png</PreviewImage>
<SupportedProducts>
<IsolatedShell Version="7.0">Visual Studio</IsolatedShell>
</SupportedProducts>
<SupportedFrameworkRuntimeEdition MinVersion="4.6" MaxVersion="4.9"></SupportedFrameworkRuntimeEdition>
</Identifier>
<Content>
<VsPackage>XX.pkgdef</VsPackage>
</Content>
</Vsix>
Some unwanted edits:
Line1 removed: <?xml version="1.0" encoding="utf-8"?>
Line2 modified to <Vsix xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010" Version="1.0.0">
Tag "Description" got edited too..
How could I avoid this edits? I just expected the version to get modified from XXXXX to YYYYY without changing any other content through my gradle build script.
That is because XmlNodePrinter.
If xml markup declaration is needed, use XmlUtil.serialize().
def vsixmanifest = new XmlSlurper().parse(vsixmanifestFile)
vsixmanifest.Identifier[0].Version.replaceBody ( "YYYYY" )
println groovy.xml.XmlUtil.serialize(vsixmanifest)
You can quickly try the demo

What's wrong with my code snippet?

I have a code snippet that's giving me some slightly annoying problems. Here's the snippet:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Set With Notify</Title>
<Description>Code snippet for common model setters</Description>
<Shortcut>notify_member</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>type</ID>
<ToolTip>The type of both members</ToolTip>
</Literal>
<Literal>
<ID>member</ID>
<ToolTip>The member symbol</ToolTip>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[
private $type$ _$member$;
public $type$ $member$
{
get
{
return _$member$;
}
set
{
if (value != this._$member$)
{
this._$member$ = value;
this.OnPropertyChanged();
}
}
}
]]>
</Code>
</Snippet>
</CodeSnippet>
So, first issue I've already worked around but it made my snippet slightly more difficult to use: When using only 2 Declarations/Replacements the snippet would just get pasted into the editor without an opportunity to specify type, or member.
Currently, whenever I use this snippet, the two braces following my set function are not properly indented. The final brace is in the right spot and all other code is indented correctly.
So, what am I missing or doing improperly to cause this formatting issue?

Use of text() function when using xPath in dom4j

I have inherited an application that parses xml using dom4j and xPath:
The xml being parsed is similar to the following:
<cache>
<content>
<transaction>
<page>
<widget name="PAGE_ID">WRK_REGISTRATION</widget>
<widget name="TRANS_DETAIL_ID">77145</widget>
<widget name="GRD_ERRORS" />
</page>
<page>
<widget name="PAGE_ID">WRK_REGISTRATION</widget>
<widget name="TRANS_DETAIL_ID">77147</widget>
<widget name="GRD_ERRORS" />
</page>
<page>
<widget name="PAGE_ID">WRK_PROCESSING</widget>
<widget name="TRANS_DETAIL_ID">77152</widget>
<widget name="GRD_ERRORS" />
</page>
</transaction>
</content>
</cache>
Individual Nodes are being searched using the following:
String xPathToGridErrorNode = "//cache/content/transaction/page/widget[#name='PAGE_ID'][text()='WRK_DNA_REGISTRATION']/../widget[#name='TRANS_DETAIL_ID'][text()='77147']/../widget[#name='GRD_ERRORS_TEMP']";
org.dom4j.Element root = null;
SAXReader reader = new SAXReader();
Document document = reader.read(new BufferedInputStream(new ByteArrayInputStream(xmlToParse.getBytes())));
root = document.getRootElement();
Node gridNode = root.selectSingleNode(xPathToGridErrorNode);
where xmlToParse is a String of xml similar to the excerpt provided above.
The code is trying to obtain the GRD_ERROR node for the page with the PAGE_ID and TRANS_DETAIL_ID provided in the xPath.
I am seeing an intermittent (~1-2%) failure (returned node is null) of this selectSingleNode request even though the requested node is in the xml being searched.
I know there are some gotchas associated with using text()= in xPath and was wondering if there was a better way to format the xPath string for this type of search.
From your snippets, there is a problem regarding GRD_ERRORS vs. GRD_ERRORS_TMP and WRK_REGISTRATION vs. WRK_DNA_REGISTRATION.
Ignoring that, I would suggest to rewrite
//cache/content/transaction/page
/widget[#name='PAGE_ID'][text()='WRK_DNA_REGISTRATION']
/../widget[#name='TRANS_DETAIL_ID'][text()='77147']
/../widget[#name='GRD_ERRORS_TEMP']
as
//cache/content/transaction/page
[widget[#name='PAGE_ID'][text()='WRK_REGISTRATION']]
[widget[#name='TRANS_DETAIL_ID'][text()='77147']]
/widget[#name='GRD_ERRORS']
Just because it makes the code, in my eyes, easier to read, and expresses what you seem to mean more clearly: “the page element that has children with these conditions, and then take the widget with this #name.” Or, if that is closer to how you think about it,
//cache/content/transaction/page/widget[#name='GRD_ERRORS']
[preceding-sibling::widget[#name='PAGE_ID'][text()='WRK_REGISTRATION']]
[preceding-sibling::widget[#name='TRANS_DETAIL_ID'][text()='77147']]

Listening for dataChange event in AdvancedDataGrid

This is my code:
<controls:AdvancedDataGrid id="adg" dataChange="adg_dataChangeHandler(event)">
<!-- other stuff goes here -->
</controls:AdvancedDataGrid>
and in my ActionScript code:
protected function adg_dataChangeHandler(event:FlexEvent):void
{
trace(1);
}
When I edit a cell in advancedDataGrid (making the columns editable of course) it never dispatches an event. Or, in other words, my function is never called. How can I fix this?
I think that the better option for my scenario is to use an itemEditor, that has a listener put on the change event. Code looks like :
<controls:AdvancedDataGrid id="adg">
<controls:groupedColumns>
<adgs:AdvancedDataGridColumn headerText="A" wordWrap="true" dataField="name" editable="false" itemEditor="Aaa"/>
</controls:groupedColumns>
</controls:AdvancedDataGrid>
and the item editor class is here :
<?xml version="1.0" encoding="utf-8"?>
<mx:TextInput xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" change="textinput1_changeHandler(event)" restrict="0-9">
<fx:Script>
<![CDATA[
protected function textinput1_changeHandler(event:Event):void
{
trace("ha");
}
]]>
</fx:Script>
</mx:TextInput>

Eclipse Contextual Help

Now can I register contextual help in an Eclipse WizardDialog/Editor.
1) I created a help_contexts.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<?NLS TYPE="org.eclipse.help.contexts"?>
<contexts>
<context id="my.plugin.help.general" >
<description>test</description>
<topic label="test" href="http://domain.com/help.html"/>
</context>
</contexts>
2) I referenced this file in my plugin.xml
<extension
point="org.eclipse.help.contexts">
<contexts file="help_contexts.xml" plugin="my.plugin.MainEditor">
</contexts>
</extension>
3) I added a line in my build.properties to include this file in the bin directory (bin.includes = help_contexts.xml, ... )
4) When running my GEF-based plugin, I see "No match found for "my.plugin.MainEditor"" under dynamic help.
I know I need to create something like this somewhere, but I don't know where to set this up for my WizardDialog or at least for my whole editor:
public void createPartControl(Composite parent) {
...
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,
"my.plugin.help.general");
}
Note: This question originally contained two questions. I have removed the first (unanswered part) to be posted elsewhere.
Here is how you do it:
1) I created a help_contexts.xml file. Don't have periods in the context id. Don't include your plugin name in there.
<?xml version="1.0" encoding="UTF-8"?>
<?NLS TYPE="org.eclipse.help.contexts"?>
<contexts>
<context id="help_general" >
<description>test</description>
<topic label="test" href="http://domain.com/help.html"/>
</context>
</contexts>
2) I referenced this file in my plugin.xml Don't include the plugin-id if you are referencing your own plugin.
<extension
point="org.eclipse.help.contexts">
<contexts file="help_contexts.xml">
</contexts>
</extension>
3) I added a line in my build.properties to include this file in the bin directory (bin.includes = help_contexts.xml, ... ). Note your Bundle-SymbolicName in your Manifest.MF (also visible in your plugin.xml editor). Example: my.plugin
4) Set the context id in the WizardPage (credit goes to #VonC)
public class MyWizardPage extends WizardPage
public void createControl(Composite parent) {
PlatformUI.getWorkbench.getHelpSystem.setHelp(parent, "my.plugin.help_general");
}
}
For the main question, I am not sure about your setHelp second parameter. See this thread:
In the method call
PlatformUI.getWorkbench().getHelpSystem().setHelp()
second parameter is the contextID.
It should be prefixed with the pluginID like : "pluginID.contextID".
Now I was not sure where to find the plug-in ID for my plug-in.
So I used the value of this property : Bundle-Name Bundle-Symbolic-Name from MANIFEST.MF as the plug-in ID.
Now it works.
For the sidenote (help for WizardDialog), this thread might help (from David Kyle
and his blog "Eclipse RCP"):
We set the context id in our wizard page.
public class MyWizardPage extends WizardPage
public void createControl(Composite parent) {
PlatformUI.getWorkbench.getHelpSystem.setHelp(parent,
MyPluginActivator.ID + ".mycontexthelpid");
}
}
and we set help for the wizard dialog.
WizardDialog dialog = new WizardDialog(.....);
PlatformUI.getWorkbench().getHelpSystem().setHelp(dialog.getShell(),
"mycontexthelp.id");
We don't override performHelp().
As for the help context id. Define a context xml file in your plugin.
<?xml version="1.0" encoding="UTF-8"?>
<?NLS TYPE="org.eclipse.help.contexts"?>
<contexts>
<context id="mycontexthelpid" >
<description>My wizard help.</description>
<topic label="Wizard help" href="reference/wizard/help.xhtml"/>
</context>
</contexts>
in your plugin
<plugin>
<extension point="org.eclipse.help.contexts">
<contexts file="mywizard.xml" plugin="com.mypluginid"/>
</extension>
</plugin>
A common problem is messing up the plugin and context help ids. You can set
a couple of break points to see which context id is being requested.

Resources