Blackberry development: how to get XMLReader SAXParser - blackberry

I'm looking to port my working Android XML parser to Blackberry, but the latter's Java feature set isn't as rich? I didn't want to have to write two parsers.
The following code yields "The method getXMLReader() is undefined for the type SAXParser":
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
Am I just out of luck here?
It's true I am trying to use org.xml.sax. I've read all the XML parsing discussions I can find out there. I wonder now if I can do this? Should I be using org.kxml2 instead because org.xml.sax makes no sense in BlackBerry land?
Thanks for any advice!
Russ

You don't need to use the getXmlReader() method.
Now that you have your SAXParser use it to parse a document or stream.
SaxParserFactory spf = SaxParerFacter.newInstance();
SAXParser parser = spf.newSAXParser();
Open your stream or file and call and assign it to a variable. Let's call ours input.
parser.parse(input, handler)
The handler file will implement all of the call backs to handle the events the parser encounters.
I found this explanation of SAX to be quite helpful.

I'll answer this though I suspect there are others who know better.
My assessment of BlackBerry is that it's very poor in its API set. So, the SAX XML parser isn't available as it is on Android. Okay, that's cool. It's older and from a "smaller" time.
Worse though, it appears very challenging even to add a third-party library to a BlackBerry application. I followed various posts out there and failed to incorporate my own "third-party" JAR convincingly into a BlackBerry project despite the collective wisdom of a number of web pages on the topic.
I was thinking then of writing my own parsing engine to replace SAXParser.parse(). How hard could it be since my expectations for it are childishly simple?
Very hard indeed since it appears that the JavaME support for java.lang.Class is impoverished as well; it doesn't support the important reflection methods such as getDeclaredMethods() for use in creating the engine (into which I naturally wanted to plug my existing XML parser-handler).
Alas, this makes me wonder just what BlackBerry apps out there are able to do? I'm probably giving this world short shrift, but a couple of days were sufficient for me to go from zero to parsing XML texts off the web on Android, so I expected a very easy time of it here too.
Please feel free to shred my answer. If you can and do, especially if you add a real one, it will doubtless greatly benefit other folk new to BlackBerry development including me later when I come back to the problem (so that I can avoid brute-force stringing through the XML stream instead of cleanly parsing it).

Related

Connect to Acrobat's IAC (interapplication communication)

I am trying to automate some non-trivial task* with Adobe's Acrobat XI.
I think the way to go is using Acrobat's IAC, which seems to be well-documented, eg. here.
However, I could not figure out how to access the application object, eg. from within an HTA. I mean: How do I get the app object mentioned in the API documentation?
It feels like I am missing something very obvious. However, I have been searching and trying unsuccessfully for quite a while now.
Alternatively, any other suggestion how to perform complicated stuff (see footnote) in Acrobat is appreciated.
*The task is concatenating 1 to n JPG files into a PDF/A document (like, tens of thousands of times). The mapping is given through a TSV file or something alike. The requirement of generating PDF/A which pass Adobe's validation forces me to use Acrobat, at least for this last step.
Are you using .net? Are you missing a reference to IAC?
try: SET gApp = CreateObject("AcroExch.App")

Silent Printing with TideSDK

UPDATE: I've decided to use appjs for my project, rather than TideSDK. With AppJS, you are able to easily make node modules, in which you can add C++ modules for easy use of silent printing. I'd recommend anyone interested in the topic to check it out. Best of luck to you all!
I'm developing an application with TideSDK - It's a really awesome framework, if you haven't tried it, set some time aside!
Anyway, I'm attempting to print using Javascript, but a Print Settings dialog comes up each time, as it would with other browsers. I'm trying to eliminate that box as well as pass along the printer I would like it to print with.
I'm aware that there are settings in FireFox for silent printing, that is was I used previously, but there aren't any similar options for TideSDK (That I have found).
After a ton of research, I think the only viable options consist of a python script, a C++ module or editing the TideSDK source and recompiling. All three sound like loosers to me. Modifying the TideSDK source and removing the dialog box from webkit_ui_delegate.cpp will most likely result in some issues when updating this program down the road - in addition to not being able to pass the printer name easily. The python script would require third party modules and would have to process the contents of the page, I doubt I would be able to write something that could do a quality job in that respect. Finally, I think the C++ solution is the most feasible since it has access to win32api, but again, it would have to process HTML to a print language, something i'm not familiar with. I guess i'm looking for more of a webkit solution that handles the rendering for me.
What should I do to implement silent printing on TideSDK? Please include code examples.
I'm looking for a windows solution primarily, I've already figured out
the other platforms.
Thank you for your time and I appreciate the feedback!
NOTE: this is a rewrite of an earlier question.
The way Windows/GDI+ printing works is that it uses a PrintDialog to obtain a printer identifier (and to also let the user know what printer they are printing to). So in order to have silent printing, you need to obtain a printer identifier without showing a dialog.
So REMOVE this code:
// Open a printing dialog to fetch the HDC of the desired printer.
PRINTDLG dialog;
ZeroMemory(&dialog, sizeof(PRINTDLG));
dialog.lStructSize = sizeof(PRINTDLG);
dialog.Flags = PD_PRINTSETUP | PD_RETURNDC;
BOOL dialogResult = ::PrintDlg(&dialog);
if (!dialogResult) // Error or cancel.
{
DWORD reason = CommDlgExtendedError();
if (!reason) // User cancelled.
return S_OK;
logger->Error("Could not print page, dialog error code: %i",
reason);
return E_FAIL;
}
HDC hdc = dialog.hDC;
And then replace the last line (HDC hdc = ...) with some other way of getting a printer HDC. You could use GetDefaultPrinter() to get the name of the default printer, and then get a HDC using CreateDC().
Optionally, you could select a printer or create a custom print dialog using the EnumPrinters() function.
Sad to see this question didn't get any quality answers, this is something I wanted to implement myself.
I think it would be quite a venture to invest the time required to get this feature working with TideSDK. Because of that, I'm going to stray away from the core competencies of the question and recommend that you try a framework other than TideSDK to accomplish this. I think that is the most realistic solution to this problem, and it will be the one that I take.
I'll update this answer once I find the framework I'll be sticking with.

Typing code using a BlackBerry?

Is a BlackBerry feasible for writing code with?
Additionally: Are there some programming languages which are specially easy or hard to type on it's keyboard?
I don't know BB well, but I'm trying to evaluate it for writing code while commuting. AFAIK, it doesn't have a "full-featured" keybard, and there are other phones with a more complete one. But I'd also like to be able to write text single-handedly, and I believe it's possible on a BB (?).
Note: that's not a question about writing code for a BlackBerry, but rather on one.
(If that's not a good site for such a question, please let me know where could I pose it. I've let myself put it here based on the "matters that are unique to the programming profession" entry in the FAQ.)
No. Consider a netbook if you need something cheap you can write code with on-the-go. I've tried too, but mobile phones (no matter how smart they are) can't be used for writing code (unless you're willing to spend 1 hour to write a "Hello, World!" app).

Communication between delphi application and Windows NT system driver

I am trying to build a very simple driver. Its sole purpose will be to register "PsSetCreateProcessNotifyRoutine" and on callbacks recieved from kernel, notify my Win32 application about which proccesses are started and stoped.
I only know how to build such a simple driver with "DriverEntry" and "DriverUnload" and compile it with DDK. But I don't know how to actually implement communication. I know it can be done with IOCTL. But beyond that I am in the dark. I cannot find simple example of how to do that in Delphi. I only know it can be done.
So what I am looking for is some simple and understandable tutorial on how to do it or event better an example delphi program with acompaniying driver code. Maybe there are even other ways of communication.
Any help would be appriciated.
Doesn't matter if in Delphi or not. You have to use the function DeviceIoControl. Read the article in MSDN about it.
In short, you'll have to choose some IOCTL codes from the available set. Then you call DeviceIoControl with one of these codes and pass some data, and in driver you handle that request and return something else.
You can also handle standard IOCTLS, such as the ones generated by calling ReadFile or WriteFile in user-mode.
Don't look for a "tutorial how to do that in Delphi", just look for any tutorial. They're all the same, no matter the language, it's pure Win32/Native api stuff. Here's one for example, just googled it out.

What's the best way to pass data into a Flex chart from a Ruby on Rails application?

Quite a few methods exist for passing data into a Flex binary from a Rails application. Right now, I'm using the old e4x resultFormat with a xml.erb template. I've done AMF before, but I feel like inlining parameters into the embed itself is a better solution because you don't have to wait for the browser to load a swf binary and the binary to make a web request.
Taking all of that into account, what is the best practice for rendering a Flex widget with a Rails back-end these days?
Sounds to me like you shouldn't use Flex at all. Flex is great for writing applications that load and display data, but is a huge overhead if you just want to display charts. If you're worried about delivering the SWF and the data in two separate responses, you should be worrying about the 200-300 K overhead of the Flex framework.
Go with something more lightweight like Flot and deliver the JavaScript code that generates the charts along with the data. I don't think Flex is a suitable platform for what you want.
If the chart is just a graphic you are placing amidst normal html content, your solution of custom compiling the swf may be a good one. Of course you should still explore alternatives like Theo's suggestion.
If your whole application is flash, it's a toss-up. If it is fastest to simply import a swf, go ahead. However, if you need to make things any more interactive, use the data elsewhere, or fetch new data, it would probably be best to use xml templates as you are, or the ActiveRecord::Base#to_xml method if you're lazy.
It depends, are you going to want the charts to be 'live', as in get updated in real-time when data changes? If so then using AMF with a Flex native RemoteObject gives you plenty of polling options, you can also just use a simpler Flex native HTTPService.
Read about them both here: Flex Actionscript 3.0 Documentation

Resources