How to set "org.w3c.css.sac.parser" system property? - java

In this ParserFactory.java
String className = System.getProperty("org.w3c.css.sac.parser");
if (className == null) {
throw new NullPointerException("No value for sac.parser property"); //line 35
} else {
return (Parser)(Class.forName(className).newInstance());
}
When I run this DemoSAC.java file as Java Application in Eclipse, I got
Exception in thread "main" java.lang.NullPointerException: No value for sac.parser property
at org.w3c.css.sac.helpers.ParserFactory.makeParser(ParserFactory.java:35)
What exactly is the "org.w3c.css.sac.parser" property? How do I set it under Windows? What should I set it to?
Thanks!

If you don't want to modify code, you can also set a Java property in Eclipse's Java launch configuration dialog. You specify a "VM option" in the "Arguments" tab . To set the property to "org.w3c.flute.parser.Parser" as suggested by javamonkey79, you would specify:
-Dorg.w3c.css.sac.parser=org.w3c.flute.parser.Parser

It looks like you need to provide an interface implementation. Per this link here, this is one way to do it:
get the flute parser here
add it to your build path
add this to the DemoSAC class (before the getProperty call):
System.setProperty("org.w3c.css.sac.parser",
"org.w3c.flute.parser.Parser");
I don't know why it is doing this reflection based instantiation to begin with, perhaps bypassing ParserFactory and returning a new instance of the flute parser would be cleaner altogether?

Related

Possible side effects when several CommandLine instance "work" on the same instance of an annotated class?

picoCLI's #-file mechanism is almost what I need, but not exactly. The reason is that I want to control the exact location of additional files parsed -- depending on previous option values.
Example: When called with the options
srcfolder=/a/b optionfile=of.txt, my program should see the additional options read from /a/b/of.txt, but when called with srcfolder=../c optionfile=of.txt, it should see those from ../c/of.txt.
The #-file mechanism can't do that, because it expands ALL the option files (always relative to the current folder, if they're relative) prior to processing ANY option values.
So I'd like to have picoCLI...
process options "from left to right",
recursively parse an option file when it's mentioned in an optionfile option,
and after that continue with the following options.
I might be able to solve this by recursively starting to parse from within the annotated setter method:
...
Config cfg = new Config();
CommandLine cmd = new CommandLine(cfg);
cmd.parseArgs(a);
...
public class Config {
#Option(names="srcfolder")
public void setSrcfolder(String path) {
this.srcfolder=path;
}
#Option(names="optionfile")
public void parseOptionFile(String pathAndName) {
// validate path, do some other housekeeping...
CommandLine cmd = new CommandLine(this /* same Config instance! */ );
cmd.parseArgs(new String[] { "#"+this.srcfolder + pathAndName });
}
...
This way several CommandLine instances would call setter methods on the same Config instance, recursively "interrupting" each other. Now comes the actual question: Is that a problem?
Of course my Config class has state. But do CommandLine instances also have state that might get messed up if other CommandLine instances also modify cfg "in between options"?
Thanks for any insights!
Edited to add: I tried, and I'm getting an UnmatchedArgumentException on the #-file option:
Exception in thread "main" picocli.CommandLine$UnmatchedArgumentException: Unmatched argument at index 0: '#/path/to/configfile'
at picocli.CommandLine$Interpreter.validateConstraints(CommandLine.java:13490)
...
So first I have to get around this: Obviously picoCLI doesn't expand the #-file option unless it's coming directly from the command line.
I did get it to work: several CommandLine instance can indeed work on the same instance of an annotated class, without interfering with each other.
There are some catches and I had to work around a strange picoCLI quirk, but that's not exactly part of an answer to this question, so I explain them in this other question.

How to enable the Barcode recognization in Abbyy Fine Reader Engine 12?

Barcode recognition is disabled by default in Abbyy Fine Reader Engine 12.
In order to enable it, I need to set the DetectBarcodes property of the PageAnalysisParams Object to TRUE.
Can anyone please help me, how can I set this property true in my java code sdk?
This is the property which we have to set:
public native void setDetectBarcodes(boolean arg0);
How can we call the native function from the java code?
Because calling directly with the object it is giving error.
Error: The local variable pageAnalysisParams may not have been initializedJava(536870963)
To get/initalize an instance of IPageAnalysisParams you can:
IPageAnalysisParams pageAnalysisParams = engine.CreatePageAnalysisParams();
You can also obtain an instance from "document processing params", like:
IDocumentProcessingParams documentparams = engine.CreateDocumentProcessingParams();
IPageAnalysisParams pageAnalysisParams = documentparams.getPageProcessingParams().getPageAnalysisParams();
source: https://github.com/search?q=IPageAnalysisParams&type=code
Looking at the public code samples, you should:
Obtain an instance of IDocumentProcessingParams (dpParams).
Tune that object (and sub-objects(page analysis params)).
And pass that to: document.Process(dpParams);
As #xerx593 suggested, programatically tuning document processing params is a perfectly valid answer.
Another valid answer is to use a configuration file, for example custom_barcode_profile.ini, and fill it according to your needs. This allows you to have better control and readibility over your profiles:
...
[PageAnalysisParams]
DetectBarcodes = TRUE
...
Use your ABBYY SDK documentation and/or ABBYY java wrapper classes to fine tune other parameters, then instead of using document.Process(dpParams);, instantiate an engine object and pass your custom_barcode_profile.ini file to it:
IEngine engine = Engine.InitializeEngine(<your sdk & license params>);
engine.LoadProfile("custom_barcode_profile.ini");
IFRDocument document = engine.CreateFRDocument();
document.AddImageFile("document.png", null, null);
document.Process(null);
document.Export("result.xml", FileExportFormatEnum.FEF_XML, null);
You cannot programatically "mix" multiple predefined profiles into one, you need to add parameters to a custom profile or even create another one and pass it to your engine object.
To enable table detection in the profile we defined later, look for parameters that affects table detection in the documentation, such as DetectTables, and add it to your custom profile:
...
[PageAnalysisParams]
DetectBarcodes = TRUE
DetectTables = TRUE
...

Accessing File property folderType

I notice that the File class has a property called folderType, but I cannot see anyway to get this String at run-time. Is there a way? Edit: perhaps it's not part of File.
When I rest my mouse over file in the fileIO.open
The object you have there is a Win32ShellFolder2, which is a subclass of ShellFolder, which is a subclass of java.io.File. ShellFolder defines a getter named getFolderType() which returns the folder type as a string.
So you could get the contents of the field like this:
file = fileChooser.getSelectedFile();
if (file instanceof ShellFolder) {
ShellFolder sf = (ShellFolder)file;
String folderType = sf.getFolderType();
ShellFolder and Win32ShellFolder2 are in the package sun.awt.shell. This package isn't part of the standard Java API, so it could change from one JVM to another or from version of the JVM to another. See With what should I replace sun.awt.shell.ShellFolder so I don't get compile warnings?.
There are many ways one of them is this MimetypesFileTypeMap().getContentType(file)
and i think fileio is object of class Win32ShellFolder2,this has a public function getFolderType() as mentioned here
so you can use it like this i feel
fileIO.open(file).getFolderType()

UFT/QTP: Count child objects in Java Internal Frame

I need to compare a string with all values of my text fields that are inside in a Java Internal Frame.
I already tried to use this code:
Dim getElement
Set getElement = Description.Create
getElement("class description").value = "text box"
'I tried different class names: "OracleTextField", "JavaEdit"
'getElement("micclass").value = "OracleTextField"
'getElement("micclass").value = "JavaEdit"
Set obj = Browser("xxxx").JavaApplet("Main").JavaInternalFrame("yyyy").ChildObjects(getElement)
total = obj.Count
' For loop goes here
total returns 0 all the time.
Can you tell me what I'm doing wrong?
If you need something more let me know.
I tried the following line and it works. Now i have total number of text fields available in Java internal frame.
getElement("to_class").value = "JavaEdit"
Following QTP documentation didn't help, but if you check your object properties inside your Object Repository you'll find all properties of each object. Instead of "micclass" try to use your property name. Mine was "to_class" with value "JavaEdit".
QTP Documentation explains why we should use "micclass" and differences between "micclass" and "Class Name". However none of them worked for me. I used "to_class" property and it works fine!
I'm working with UFT v12.02

JavaScript scope resolve time

I'm writing an app that loads javascript dynamically using rhino(or a browser); I got 2 files:
// in a file called fooDefinition.js
var definition = {
foo: function(data){return bar(data)},
loadFile: "barLib.js"
}
now, bar() is defined like this:
// in a file called barLib.js
function bar(data){
return data + " -> bar!";
}
This is what I want to do:
load fooDefinition.js into the environment
read the value of loadFile (in this case: "barLib.js") and load the file (NOTE: load the file through external mechanism, not through javascript itself!)
call foo
external mechanism & example usage (Java pseudo code):
// assume engine is a statefull engine (rhino for example)
String str = /*content of fooDefinition.js*/;
engine.eval(str);
String fileToLoad = engine.eval("definition.loadFile");
engine.load(IOUtils.readFileToString(new File(fileToLoad)));
String result = engine.eval("definition.foo('myData')");
I've tried this in Google Chrome's JS console and no error was thrown
I wonder is this the correct way of accomplish such task?
TL;DR:
Are the attributes of an object loaded and checked when the object is defined?
If your engine is statefull that is it keeps track of defined variables, yes your approach is corrent and will work as expected
But if it is not, your way will fail, because when you call the following
String fileToLoad = engine.eval("definition.loadFile");
your engine haven't any info about definition object and as a result it return an exception (in JavaScript).
It seems your engine is statefull and all things will work correctly

Categories

Resources