Norconex / importer

Norconex Importer is a Java library and command-line application meant to "parse" and "extract" content out of a file as plain text, whatever its format (HTML, PDF, Word, etc). In addition, it allows you to perform any manipulation on the extracted text before using it in your own service or application.
http://www.norconex.com/collectors/importer/
Apache License 2.0
33 stars 23 forks source link

no such function "toUpperCase" #35

Closed angelo337 closed 8 years ago

angelo337 commented 8 years ago

hi there sorry to bother you but I am having an issue with the script bellow

           <transformer class="com.norconex.importer.handler.transformer.impl.ScriptTransformer">
                    <script><![CDATA[
                    empresas = metadata.getString('empresas');
                    consorcios_UT = metadata.getString('consorcios_UT');
                    consorcios_UT = consorcios_UT.toUpperCase();
                    metadata.setString('consorcios_UT', consorcios_UT);
                    metadata.setString('empresas', empresas);
            ]]></script>
            </transformer>

after running the script I am getting and error saying that is not a 'toUpperCase()' defined:

Caused by: :3 TypeError: null has no such function "toUpperCase" at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57) at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:213) at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:185) at jdk.nashorn.internal.runtime.ECMAErrors.typeError(ECMAErrors.java:172) at jdk.nashorn.internal.runtime.linker.NashornBottomLinker.linkNull(NashornBottomLinker.java:180) at jdk.nashorn.internal.runtime.linker.NashornBottomLinker.getGuardedInvocation(NashornBottomLinker.java:66) at jdk.internal.dynalink.support.CompositeGuardingDynamicLinker.getGuardedInvocation(CompositeGuardingDynamicLinker.java:124) at jdk.internal.dynalink.support.LinkerServicesImpl.getGuardedInvocation(LinkerServicesImpl.java:154) at jdk.internal.dynalink.DynamicLinker.relink(DynamicLinker.java:253) at jdk.nashorn.internal.scripts.Script$^eval_.:program(:3) at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637) at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494) at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:418)

could you please check that for me? thanks

essiembre commented 8 years ago

You try to call a function on a null value. Check for null first, or use metadata.getString('empresas', 'anyDefaultString') to make sure null is never returned. Alternatively, you can use the CharacterCaseTagger to avoid relying on scripting for this.

angelo337 commented 8 years ago

hi there
after working on this problem this weekend I figure it out. the problem is that the JS implementation in JAVA do not cast automatic all variables so in order to make it work I have to cast that variable that is failing.

thanks for your help angelo