Modifying findGrep results when using lookaheads/lookbehinds [JS][CS6]

Dear all,
I am thinking about a search/replace script (JS) in which the user is able to choose in a GUI to which elements of a findGrep()-array a changeGrep() method should be applied to. All in all that should be an easy thing to do.
The only thing I am wondering about is dealing with lookaheads and lookbehinds. Assuming the findWhat expression to be " (?=!)" to find a single unwanted space in front of an exclamation mark. Please understand this just as a simple example, it is obvious that you can do that kind of simple search without using a lookahead. The findGrep array will contain the pointer to the found space. If the user decides to remove the space and applies the changeGrep method on it, no changes will be made because the exclamation mark is not stored in the findGrep array and hence changeGrep method will not match the space.
So I am thinking of extending the pointer/selection before using changeGrep to include the exclamation mark in order to successfully apply changeGrep. But maybe there is a more straight solution I am not aware of?
Would be glad to read your point of view here.
Thank you very much!
Jan

HH_BFS wrote:
Hey pixxxel schubser,
many thanks for your reply! I think I am causing confusion when not showing any code. The script still is an idea, so there is nothing to present. But maybe these lines will illustrate my problem. And to underline it, please let me tell again, that my question adresses doing specific changes when using lookaheads/lookbehinds in general. The given bloody example with space and exclamation mark is really just an simple illustration.
//now (in my opinion) the problem: 
//but found[0] only contents " " (space). so the changeGrep method will not match, because the "!" is missing. Nothing changes. 
//it is clear to me that this happens because the findGrep method finds matching content in which the changeGrep tries a second find with replace. that can not work well. 
//so i would be happy, if i could just give up the findGrep method and tell the changeGrep method only to change i.e. the first (or second ... or whatever) match. But I think that is not possible. 
A little suggestion:
// required: opened document with one text frame
// with contents e.g. The search for the "h" in the middle of the first "the"
// and show text before and behind (in Javascript-Console)
var aDoc = app.activeDocument;
var aTF = aDoc.textFrames[0];
var found = aTF.contents.match(/(\w+ )(t)(h)(e)( \w+)/);
$.writeln(found);
$.writeln(RegExp.$1 + "  |  " + RegExp.$2 + "  |  " + RegExp.$3 + "  |  " + RegExp.$4 + "  |  " + RegExp.$5 );
Try it out. This will be sometimes complicated for the programmer (I mean you ), but perhaps one possible way to go.
Have fun

Similar Messages

  • Incorrect Results When Using an In-Line View and User Function in 10g

    My developers are complaining of incorrect Select statement results when using an in-line view along with a user defined function. Below is the statement:
    select test_f(wo1)
    from
    (SELECT a.WORK_ORDER_NBR, b.work_order_nbr wo1/*, facility_f(A.FACILITY),
    A.PLANNER, A.WO_STATUS, mil_date(A.WO_STATUS_DATE)*, A.WORK_ORDER_TYPE,
    A.WO_DESCRIPTION
    FROM TIDWOWRK A, TIDWOTSK B
    WHERE B.WORK_ORDER_NBR(+) = A.WORK_ORDER_NBR))
    where wo1 is null;
    Test_f() is a user defined function and the above query returns thousands of rows. It should return 308 rows. It is apparent that the target database is not evaluating the "where wo1 is null;" clause.
    select to_char(wo1)
    from
    (SELECT a.WORK_ORDER_NBR, b.work_order_nbr wo1/*, facility_f(A.FACILITY),
    A.PLANNER, A.WO_STATUS, mil_date(A.WO_STATUS_DATE)*, A.WORK_ORDER_TYPE,
    A.WO_DESCRIPTION
    FROM TIDWOWRK A, TIDWOTSK B
    WHERE B.WORK_ORDER_NBR(+) = A.WORK_ORDER_NBR))
    where wo1 is null;
    In the above query return 308 rows. The user function was replaced by an Oracle function. The Where clause is now evaluated correctly.
    The query is executed from an Oracle 10g R2 database and retrieves data from a 9.2.0.6 database.
    I've seen a little information on Metalink. It appears that there was some trouble in 9i, but were fixed in a 9.2.0.6 patch. I don't see any information about a 10.2.0.2 database.
    Anyone have any experiences or a successful solution. I suspect that I will need to report this to Oracle and wait for a patch.
    Thanks,
    John

    I can only think of two reasons for this behaviour:
    1) You are executing these two queries from two different users and there is some policy on the table.
    2) The function doesn't do an upper, but returns null a lot of times, even when the input is a not null value, like this:
    SQL> create table tidwowrk
      2  as
      3  select 1 id, 'A' work_order_nbr, 'DST' facility from dual union all
      4  select 2, null, 'TRN' from dual union all
      5  select 3, 'C', 'DST' from dual
      6  /
    Tabel is aangemaakt.
    SQL> create table tidwotsk
      2  as
      3  select 'A' work_order_nbr from dual union all
      4  select 'B' from dual
      5  /
    Tabel is aangemaakt.
    SQL> create or replace function test_f (a in varchar2) return varchar2
      2  is
      3  begin
      4    return case a when 'A' then null else a end;
      5  end;
      6  /
    Functie is aangemaakt.
    SQL> select count(*)
      2    from ( SELECT a.WORK_ORDER_NBR
      3                , test_f(b.work_order_nbr) wo1
      4             FROM TIDWOWRK A
      5                , TIDWOTSK B
      6            WHERE B.WORK_ORDER_NBR(+) = A.WORK_ORDER_NBR
      7              and a.facility in ('DST', 'TRN', 'SUB')
      8         )
      9   where wo1 is null
    10  /
                                  COUNT(*)
                                         3
    1 rij is geselecteerd.
    SQL> select count(*)
      2    from ( SELECT a.WORK_ORDER_NBR
      3                , to_char(b.work_order_nbr) wo1
      4             FROM TIDWOWRK A, TIDWOTSK B
      5            WHERE B.WORK_ORDER_NBR(+) = A.WORK_ORDER_NBR
      6              and a.facility in ('DST', 'TRN', 'SUB')
      7         )
      8   where wo1 is null
      9  /
                                  COUNT(*)
                                         2
    1 rij is geselecteerd.Regards,
    Rob.

  • Do IMAQ Cast Image or IMAQ Linear averages give different results when using different computers that are running under Windows XP ?

    Hello
    I'm currently developping an image processing algorithm using Labview 7.1 and the associated IMAQ Vision tools. After several tests, I found a weird result. Indeed, I put the labview algorithm - including the IMAQ VI on the library to get sure that I use all the time the same VI - on my memory stick and used it on two different computers. I tested the same picture (still in my memory stick) and had two very different results.
    After several hours trying to understand why, I found that there were a difference between the results given by both computers at the very begining of the algorithm. Indeed, I used a JPEG file.
    To open it, I first create an Image with IMAQ Create (U8). Then, I open it.
    Then in my first sub-VI, I use IMAQ Cast Image to be sure that the picture is a U8 grayscale picture.
    Right after that, I use the IMAQ Linear Averages. The results of this VI are different on the two computers.
    I tried several time on the same picture : one computer always give me the same result but the two computers give me a different result. So there is no random variable on the results.
    So my question is : Do IMAQ Cast Image or IMAQ Linear averages give different results when using different computers that are running under Windows XP ?
    My bet is on IMAQ Cast Image but I'm not quite sure and I do not undestand why. The labview and IMAQ are the same on both computers.
    The difference between the two computer are above :
    Computer 1 :
    Pentium(R) 4 CPU 3.20GHz with a RAM of 1Go. The processor is an Intel(R).
    The OS is windows XP Pro 2002
    Computer 2 :
    Pentium(R) 4 CPU 2.80GHz with a RAM of 512Mo. The processor is an Intel(R).
    The OS is windows XP Pro 2002.
    If anybody can help me on this problem, it would be really helpful.
    Regards
    Florence P.

    Hi,
    Indeed it's a strange behaviour, could you send me your VI and your JPEG file, (or another file that reproduces) so that I could check this inthere ?
    I'll then try to find out what's happening.
    Regards
    Richard Keromen
    National Instruments France
    #adMrkt{text-align: center;font-size:11px; font-weight: bold;} #adMrkt a {text-decoration: none;} #adMrkt a:hover{font-size: 9px;} #adMrkt a span{display: none;} #adMrkt a:hover span{display: block;}
    >> Découvrez, en vidéo, les innovations technologiques réalisées en éco-conception

  • Weird results when using prompt

    I have created a report in answers. When using a normal filter condition I get one set of results. When using a prompt with the same criteria and no filter I get no results! I played around with removing/adding certain columns (all from the same subject area and same underlying physical table ie no joins involved) and answers sometimes returns results and sometimes not, depending which columns I have added into the query! We are running OBI SE1 on windows 10.1.3.2.1 (Build 070411.1900) - has anyone come across a similar problem? I fear it may be a bug in the OBI software but couldn't find anything on metalink.

    Hi Hurtn
    Can you paste the Query Log?
    Sunil S Ranka
    Blog :: http://sranka.wordpress.com
    "Superior BI is the antidote to Business Failure"

  • Error in results when using cfqueryparam

    I get an error in the result set when using cfqueryparam in a
    SQL "IN" statement.
    This is on RHE with CFMX 6.01 and an Oracle 10g DB
    In this instance, the query should have returned 8
    records...as confirmed using SQL Navigator
    This works fine regardless of the number of prameters inthe
    list contained in variables.mrkt_sctr:
    and rms.mrkt_sctr_id in (#variables.mrkt_sctr#)
    If I do this:
    and rms.mrkt_sctr_id in (<cfqueryparam
    cfsqltype="cf_sql_varchar" list="yes" separator=","
    value="#variables.mrkt_sctr#">)
    I only get 7 results(debug info says seven and there are only
    7 records listed)...the results that would have been generated by
    the second parameter in the list of market sectors is ignored int
    he results. If a 3rd market sector is added, I see the results of
    the 1st 2 market sector id's...but the 3rd is ignored. If I put the
    query (as output by the CF debug info) into SQL Navigator and
    replace the ?'s withthe actual values...I get the appropriate
    number of results. IF you look at the results on the webpage, the
    results that would have been generated by the 3rd parameter are
    missing.
    There is nothing else in the code that would limit the number
    of rows rerturned by the query.
    Any Ideas?
    Thanks
    Eric Roberts
    Owner/ColdFusion Developer
    Three Ravens Consutling
    http://www.threeravensconsulting.com

    Do you know how to use the 'result' parameter of the query
    tag to get
    the actual, complete SQL statement sent to the database.
    Looking at
    this may tell you what your issue is.

  • Regular Expression: Different results when using FIND or regex classes

    Hi,
    has anybody an idea why the FIND REGEX statement and the regex class delivers different results when searching for
    ^\*
    in
    I try to find every place with an asterisk as first sign of the line.
    The FIND statement
    DATA gv_string        TYPE        string.
    DATA gv_pattern       TYPE        string.
    DATA gt_match_result  TYPE        match_result_tab.
    gv_string = '****'.
    gv_pattern = '^\*'.
    FIND ALL OCCURRENCES OF REGEX gv_pattern
                               IN gv_string
                          RESULTS gt_match_result.
    returns one hit as expected. But the class cl_abap_regex and cl_abap_matcher returns four hits in this example:
    DATA gv_string        TYPE        string.
    DATA gv_pattern       TYPE        string.
    DATA gt_match_result2 TYPE        match_result_tab.
    DATA gx_regex         TYPE REF TO cl_abap_regex.
    DATA gx_matcher       TYPE REF TO cl_abap_matcher.
    gv_string = '****'.
    gv_pattern = '^\*'.
    TRY.
        CREATE OBJECT gx_regex
          EXPORTING
            pattern = gv_pattern.
      CATCH cx_sy_regex .
        BREAK-POINT.
        EXIT.
    ENDTRY.
    TRY.
        CREATE OBJECT gx_matcher
          EXPORTING
            regex = gx_regex
            text  = gv_string.
      CATCH cx_sy_matcher .
        BREAK-POINT.
        EXIT.
    ENDTRY.
    gt_match_result2 = gx_matcher->find_all( ).
    BREAK-POINT.
    Looks like the class doesn't consider the start of line symbol (^). Is there an error in my implementation?
    Any help is appreciated.
    Matthias

    Hi Jim,
    thank you for your reply. But to negate a value set of single characters you have to use
    [^  ]
    I used just the character
    ^
    This is defined as anchor character for the start of a line (See the documentation link you posted -> chapter 'Special characters for search strings') .
    As I understand it, should the FIND REGEX statement does the same as the CL_ABAP_REGEX and CL_ABAP_MATCHER classes. Therefore, I do not understand, why both implementations deliver another result.
    And I didn't find an answer for that. Does anyone else?
    Matthias

  • Content Query not producing results when using [Me] filter

    Hi
    I'm using a Content Query web part and I'm trying to show the most recent document modified by each site user by applying it across the site collection and using the Filter, Modified By [_Hidden] equals [Me]. However, this doesn't seem to work for any user
    - the web part is always blank. I have tried different combinations such changing equals to contains, and using the Modified By field etc - nothing gives me the correct results. If I instead take the [Me] out and instead use the "people chooser"
    and set to a specific person then I seem to get the results I would expect - however I cannot hard code a given user.
    Does anyone know how to use [Me] correctly?
    Thanks

    Hi  sjb500,
    According to your description, please take steps as below to meet your demand:
    With the page layout open in Design view, double-click the Content Query Web Part.
    In the Content Query Web Part dialog box, click the plus sign (+) next to Query to expand it.
    In the Source section, click Show items from all sites in this site collection.
    In List Type section, in the Show items from this list type, click Document Library.
    In the Content Type section, in the Show items of this content type group list, click Document
    Content Types.
    In the Content Type section, in the Show items of this content type list, click Document.
    In the Additional Filters section, under Show Items When, click Modified By [_Hidden] in
    the first box, click Is Equal To in the second box, and then click [Me].
    In the Content Query Web Part dialog box, click the plus sign (+) next to Presentation to expand it.
    In the Grouping and Sorting section, in the Sort items by list, click Modified
    and Select Show items in descending order.
    Click OK.
    Reference:http://office.microsoft.com/en-us/sharepoint-designer-help/display-data-from-multiple-lists-with-the-content-query-web-part-HA010174134.aspx
    [Me] is a variable that stands for the user who is currently viewing the page that contains the Content Query Web Part in the browser.
    Here is some scenarios using [Me] in Content Query Web Part:
    http://social.technet.microsoft.com/Forums/en-US/346ffbe6-d7ba-467e-b7f5-6d6e289677a1/user-tasks-web-part
    Please inform me freely if you have any questions.
    Thanks

  • Inconsistent results when using queries with UDF

    I have the following query that I can not get consistent results. Sometimes it will get the correct result but at other times it does not. I can not figure out what I am doing wrong.
    The scenario is I have on the BP Contact several UDF that we are storing sales territory information. We want to pull based on the SalesRepNo the RegName. We have 2 user defined tables set up. I can accurately pull info when I am linking to the SLS_Person_Region table. On that table there is a field called region (a number). I am trying to use that number and pull the name from the Region_Major_reg table.
    SELECT T0.[U_RegName] FROM [dbo].[@REGION_MAJOR_REG]  T0 INNER JOIN  [dbo].[@SLS_PERSON_REGION]  T1 ON T1.U_Region = T0.U_Region INNER JOIN ocpr T2 on T1.[U_SlsPerNum] = T2.[U_SalesRepNo]
    WHERE  T1.U_SlsPerNum = $[OCpr.U_SalesRepno]
    What is frustrating is that the query works fine for different terrioties.
    Any help would be appreciated.
    Thanks
    Steve

    the scheme is the first tow indicate the territory
    The next two digits represent the rep
    When a rep is replaced we assign an open territory or the next rep the next number
    an example is 0105 was an open territory when we signed a new rep we gave them 0106
    To answer your question we have nine
    0106
    0205
    0303
    0401
    0503
    0602
    0702
    0801
    0904
    I think that is what you are asking

  • Missing results when using percentage function %GT

    Hi all,
    I'm using the percentage function in BEx. As you can see in the left two columns, it works fine when the results are higher then 0,4. All the results less than 0,4 are set to 0. In the last column I calculated the results with an Excel formula. 
    Any Idea, what the problem can be?
    4.392,080          1,5635 %          1,563481163
    997,440          0,0000 %          0,355066085
    4.761,680          1,6951 %          1,695050405
    1.260,000          0,4485 %          0,448531508
    469,600          0,0000 %          0,167166981
    280.916,720     100,0000 %          
    280.916,720     100,0000 %          
    Many thanks in advance!

    Dear Daya sagar,
      Iam tried with taht functionality  the query it self it is showing wrong and iam getting below error as result.
    Diagnosis
    The query contains a formula with the operator %RT. Therefore, the query cannot be released for OLE DB for OLAP.
    The operators %GT, %RT, %CT, SUMGT, SUMRT, SUMCT and LEAF depend on the display of the list in the BEx Analyzer. If you used OLE DB for OLAP or MDX, this formula would deliver unexpected values.
    Procedure
    Do not release the query for OLE DB for OLAP, or do not use the operators %GT, %RT, %CT, SUMGT, SUMRT, SUMCT or LEAF. You may be able to achieve the desired result by selecting constants.
    and report output is not coming.
    Thanks & Regards,
    Sathish

  • Duplicate messages in search results (when using Smart Mailboxes, etc)

    I've recently started using Search Folders more and more in Mail.app
    I've encountered this very annoying bug/feature, where duplicate messages show up in a search (inside Mail). The duplicate messages are showing up multiple times (once, for each Smart Mailbox they reside in) as well as their physical Mailbox, as well as "All Mail".
    The lowdown:
    Mac OS X Leopard (10.5.4 Build 9E17)
    Dual 1.25 GHz PowerPC G4 -----(shut up! it still rocks w/my multiple 23'' apple displays)
    2GB RAM
    Mail.app Version 3.3 (926.1/926)
    This feature/bug makes it VERY difficult to find things when I'm forced to sift through at least 3 copies of any message that appears in Smart Mailboxes.
    Should I stop using Smart Mailboxes because this is a deliberate feature?
    Any suggestions or thoughts would be GREATLY appreciated.
    In a search, I think that a better way to display the multiple locations (through Smart Mailboxes, etc) that a mailbox "appears" would be to add something to the header section of a message, below everything else, or off to the right, which would indicate the Original (physical) folder a message exists in, as well as it's locations via Search Folders. This would at least eliminate the problem where they're showing up as two, three, or more COPIES within a search.
    Thanks,
    Jackson

    Hi Christiaan !
    I understand your problem. Could you set your IMAP account to avoid multiple simultaneous sessions?? maybe if there is only one session allowed per user or per time, then parallel XI threads will not be able to start downloading the messages.
    If you cannot use a longer poll interval, then you could develop an adapter module for the Mail sender adapter that could be used to verify if the current mail is just being downloaded by other thread. This adapter module could check the unique mail data (date/time + subject + etc.) against a local table.
    Regards,
    Matias.
    PD: please award points if helpful.
    Message was edited by:
            Matias Denker

  • Unexpected result when using Ls -L

    I'm no code warrior, and I'm studying the ATS book Mac OSX Support Essentials.
    When I type Ls -L, I get a list of the folders/directories in the home folder but not the info that the CLI returns for the book.
    Typing Ls -Le returns the exact same result as typing Ls -L.
    I've tried both multiple times.
    This discrepancy is really not helping me understand, and I MUST pass this exam. If I can't even get past chap 3, I'm dead.
    Any help will be greatly appreciated.
    DLS

    I get a list of Folders in a table format:
    test-installs-macbook-pro:~ testinstall$ Ls -L
    Desktop Movies Send Registration
    Documents Music Sites
    Downloads Pictures
    Library Public
    In the Book it returns a list format with the item type and permissions followed by number of subitems, owner, assigned group, modification date and the item's name.
    The format in the book looks like this:
    drwx----------+ 5 owner staff 170 Aug 20 15:49 Desktop
    drwx----------+ 3 owner staff 102 Aug 20 01:08 Documents
    I don't get this so I hit a brick wall for the rest of the lesson which builds upon this.
    Thanks for your help
    DLS
    Message was edited by: MacDLS

  • No search results when using custom list search

    Hi,
    I've built a custom list in SharePoint Online , which was supposed to be a new tracker. It was a combination of 3 different DBs. I combined the data in excel, scrubbed it and synced the data into my sharepoint list using Access. The question: Why
    don't I have any entries showing when I use the seach box within my list? It comes up with nothing found? I don't have SharePoint Admin rights, I'm just a site owner. Which elements should I look into first to make sure that my entries are found? Any help
    will be greatly appreciated. Thank You.

    Hi WSBR.Darius,
    After you added data into the custom list, if you want to search the items, you also need to run a crawl for your content source.
    However, for SharePoint 2013 Online, continuous crawls are enabled in SharePoint Online, with crawl frequencies managed by Microsoft. You need to wait for finishing continuous crawl.
    More information about Search feature in SharePoint Online:
    https://technet.microsoft.com/en-us/library/jj819291.aspx?f=255&MSPPError=-2147217396
    In addition, as this issue is about SharePoint 2013 online, I suggest you create a new thread on Office 365 forum, more experts will assist you with SharePoint Online.
    Office 365 forum:
    http://community.office365.com/en-us/f/default.aspx
    Best Regards,
    Wendy
    Wendy Li
    TechNet Community Support

  • Can I avoid pixellated results when using Replace Color?

    Running PSE9 under Mac OS X 10.6.
    I'm editing an (originally.jpg) photo of green jewelry (on a silver necklace) with a gray background.  I want to change the gray to a pale pink. 
    At first I tried the Magnetic Lasso to select the jewelry followed by Replace Color, but the intricacies of the silver necklace and the fine wire of the (pierced)  earring hooks seemed to befuddle the Lasso into losing detail.  Then I thought I had a bright idea:  Skip the detailed selection, select the entire photo, and let the non-contiguous Replace Color do the work.  I don't know how this affects the detail of the result yet, because I'm more concerned about the approximately 3 mm pixels of a variety of colors that replaced the gray background.  Changing Fuzziness didn't remove the pixellation, and I have no idea why the variety of colors is occurring.
    Where, oh where did I go wrong?

    Here's how to get the results below:
    1. Filled in the top left of the image using the clone stamp tool
        sampling off the areas below it. (makes the grey easier to select if
        it's fairly the same all around)
    2. Used the magic wand tool with contiguous not checked and clicked on
        grey in the image.
    3. Inverted that selection; Filters>Adjustments>Invert
    4. Created a new color fill adjustment layer; Layer>New Fill Layer>Solid Color
       and picked the color in the color picker dialog (you can change the color later
       by double clicking on the color fill icon in the layers panel)
    5. You may have zoom in close and fill in any areas you don't want pink by painting
        on the solid color fill layer mask with a brush. Use a black brush to show more of the
        necklace (hide the pink).
        Use a white brush to add more pink.
    The color replacement tool doesn't work so good on images like this, that's why
    a solid color fill adjustment layer is a better choice.
    MTSTUNER
    Message was edited by: MTSTUNER

  • Inconsistent SQL results when using View with UNION-ALL and table function

    Can any of you please execute the below scripts and check the output. In the table type variable, I am adding 4 distinct object ids, where as in the result, I get only the row pertaining to last id in the table type variable. Same row is returned 4 times (4= number of values in the table type).
    This scenario is occurring in our product with a SQL with exactly same pattern. I could simulate the same issue with the sample script I have provided.
    Database version: 11.2.0.3 Enterprise Edition, Single node
    Thank you.
    CREATE TABLE TEMP_T1 AS SELECT * FROM ALL_OBJECTS;
    CREATE TABLE TEMP_T2 AS SELECT * FROM ALL_OBJECTS;
    UPDATE TEMP_T2 SET OBJECT_ID = OBJECT_ID * 37;
    CREATE UNIQUE INDEX TEMP_T1_U1 ON TEMP_T1(OBJECT_ID);
    CREATE UNIQUE INDEX TEMP_T2_U1 ON TEMP_T2(OBJECT_ID);
    CREATE OR REPLACE VIEW TEMP_T1T2_V AS
    SELECT * FROM TEMP_T1 UNION ALL SELECT * FROM TEMP_T2;
    CREATE OR REPLACE TYPE TEMP_OBJ_TYPE AS OBJECT (OBJ_ID NUMBER);
    CREATE OR REPLACE TYPE TEMP_OBJ_TAB_TYPE IS TABLE OF TEMP_OBJ_TYPE;
    SET SERVEROUTPUT ON;
    DECLARE
    TYPE TEMP_T1T2_V_ROW_TAB_TYPE IS TABLE OF TEMP_T1T2_V%ROWTYPE;
    TEMP_T1T2_V_ROW_TAB TEMP_T1T2_V_ROW_TAB_TYPE;
    TEMP_OBJ_TAB TEMP_OBJ_TAB_TYPE := TEMP_OBJ_TAB_TYPE();
    PROCEDURE ADD_TO_TEMP_OBJ_TAB(OBJ_ID IN NUMBER) IS
    BEGIN
    TEMP_OBJ_TAB.EXTEND;
    TEMP_OBJ_TAB(TEMP_OBJ_TAB.LAST) := TEMP_OBJ_TYPE(OBJ_ID);
    END;
    BEGIN
    ADD_TO_TEMP_OBJ_TAB(100);
    ADD_TO_TEMP_OBJ_TAB(116);
    ADD_TO_TEMP_OBJ_TAB(279);
    ADD_TO_TEMP_OBJ_TAB(364);
    DBMS_OUTPUT.PUT_LINE('=====================');
    FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
    LOOP
    DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('---------------------');
    SELECT * BULK COLLECT INTO TEMP_T1T2_V_ROW_TAB
    FROM TEMP_T1T2_V VW
    WHERE ((VW.OBJECT_ID) IN (SELECT OBJ_ID
    FROM TABLE(CAST(TEMP_OBJ_TAB AS TEMP_OBJ_TAB_TYPE))));
    FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
    LOOP
    DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('---------------------');
    IF TEMP_T1T2_V_ROW_TAB.COUNT > 0 THEN
    FOR I IN TEMP_T1T2_V_ROW_TAB.FIRST..TEMP_T1T2_V_ROW_TAB.LAST
    LOOP
    DBMS_OUTPUT.PUT_LINE(TEMP_T1T2_V_ROW_TAB(I).OBJECT_ID||' : '||TEMP_T1T2_V_ROW_TAB(I).OBJECT_NAME);
    END LOOP;
    ELSE
    DBMS_OUTPUT.PUT_LINE('NO ROWS RETURNED!');
    END IF;
    DBMS_OUTPUT.PUT_LINE('---------------------');
    END;
    /

    I can reproduce it:
    SQL*Plus: Release 11.2.0.3.0 Production on Tue Oct 30 14:05:39 2012
    Copyright (c) 1982, 2011, Oracle.  All rights reserved.
    Enter user-name: scott
    Enter password:
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> select  *
      2    from  v$version
      3  /
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for 64-bit Windows: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    SQL> CREATE TABLE TEMP_T1 AS SELECT * FROM ALL_OBJECTS;
    Table created.
    SQL>
    SQL> CREATE TABLE TEMP_T2 AS SELECT * FROM ALL_OBJECTS;
    Table created.
    SQL>
    SQL> UPDATE TEMP_T2 SET OBJECT_ID = OBJECT_ID * 37;
    72883 rows updated.
    SQL>
    SQL> CREATE UNIQUE INDEX TEMP_T1_U1 ON TEMP_T1(OBJECT_ID);
    Index created.
    SQL>
    SQL> CREATE UNIQUE INDEX TEMP_T2_U1 ON TEMP_T2(OBJECT_ID);
    Index created.
    SQL>
    SQL> CREATE OR REPLACE VIEW TEMP_T1T2_V AS
      2  SELECT * FROM TEMP_T1 UNION ALL SELECT * FROM TEMP_T2;
    View created.
    SQL>
    SQL> CREATE OR REPLACE TYPE TEMP_OBJ_TYPE AS OBJECT (OBJ_ID NUMBER)
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE TEMP_OBJ_TAB_TYPE IS TABLE OF TEMP_OBJ_TYPE
      2  /
    Type created.
    SQL> SET SERVEROUTPUT ON;
    SQL>
    SQL> DECLARE
      2  TYPE TEMP_T1T2_V_ROW_TAB_TYPE IS TABLE OF TEMP_T1T2_V%ROWTYPE;
      3  TEMP_T1T2_V_ROW_TAB TEMP_T1T2_V_ROW_TAB_TYPE;
      4  TEMP_OBJ_TAB TEMP_OBJ_TAB_TYPE := TEMP_OBJ_TAB_TYPE();
      5  PROCEDURE ADD_TO_TEMP_OBJ_TAB(OBJ_ID IN NUMBER) IS
      6  BEGIN
      7  TEMP_OBJ_TAB.EXTEND;
      8  TEMP_OBJ_TAB(TEMP_OBJ_TAB.LAST) := TEMP_OBJ_TYPE(OBJ_ID);
      9  END;
    10  BEGIN
    11  ADD_TO_TEMP_OBJ_TAB(100);
    12  ADD_TO_TEMP_OBJ_TAB(116);
    13  ADD_TO_TEMP_OBJ_TAB(279);
    14  ADD_TO_TEMP_OBJ_TAB(364);
    15  DBMS_OUTPUT.PUT_LINE('=====================');
    16  FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
    17  LOOP
    18  DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
    19  END LOOP;
    20  DBMS_OUTPUT.PUT_LINE('---------------------');
    21  SELECT * BULK COLLECT INTO TEMP_T1T2_V_ROW_TAB
    22  FROM TEMP_T1T2_V VW
    23  WHERE ((VW.OBJECT_ID) IN (SELECT OBJ_ID
    24  FROM TABLE(CAST(TEMP_OBJ_TAB AS TEMP_OBJ_TAB_TYPE))));
    25  FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
    26  LOOP
    27  DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
    28  END LOOP;
    29  DBMS_OUTPUT.PUT_LINE('---------------------');
    30  IF TEMP_T1T2_V_ROW_TAB.COUNT > 0 THEN
    31  FOR I IN TEMP_T1T2_V_ROW_TAB.FIRST..TEMP_T1T2_V_ROW_TAB.LAST
    32  LOOP
    33  DBMS_OUTPUT.PUT_LINE(TEMP_T1T2_V_ROW_TAB(I).OBJECT_ID||' : '||TEMP_T1T2_V_ROW_TAB(I).OBJECT_NAME);
    34  END LOOP;
    35  ELSE
    36  DBMS_OUTPUT.PUT_LINE('NO ROWS RETURNED!');
    37  END IF;
    38  DBMS_OUTPUT.PUT_LINE('---------------------');
    39  END;
    40  /
    =====================
    OBJ_ID = 100
    OBJ_ID = 116
    OBJ_ID = 279
    OBJ_ID = 364
    OBJ_ID = 100
    OBJ_ID = 116
    OBJ_ID = 279
    OBJ_ID = 364
    364 : I_AUDIT
    364 : I_AUDIT
    364 : I_AUDIT
    364 : I_AUDIT
    PL/SQL procedure successfully completed.
    SQL> column object_name format a30
    SQL> select  object_id,
      2          object_name
      3    from  dba_objects
      4    where object_id in (100,116,279,364)
      5  /
    OBJECT_ID OBJECT_NAME
           100 ORA$BASE
           116 DUAL
           279 MAP_OBJECT
           364 I_AUDIT
    SQL>  Works fine in:
    =====================
    OBJ_ID = 100
    OBJ_ID = 116
    OBJ_ID = 279
    OBJ_ID = 364
    OBJ_ID = 100
    OBJ_ID = 116
    OBJ_ID = 279
    OBJ_ID = 364
    100 : ORA$BASE
    116 : DUAL
    364 : SYSTEM_PRIVILEGE_MAP
    279 : MAP_OBJECT
    PL/SQL procedure successfully completed.
    SQL> select  object_id,
      2          object_name
      3    from  dba_objects
      4    where object_id in (100,116,279,364)
      5  /
    OBJECT_ID OBJECT_NAME
          100 ORA$BASE
          116 DUAL
          364 SYSTEM_PRIVILEGE_MAP
          279 MAP_OBJECT
    SQL> select  *
      2    from  v$version
      3  /
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    SQL>SY.
    Edited by: Solomon Yakobson on Oct 30, 2012 2:14 PM

  • Detecting transform errors when using org.xml.sax.XMLFilter

    I am using javax.xml.transform.sax.SAXTransformerFactory.newXMLFilter to transform xml against a pipeline of stylesheets (See function testPipelineTransform in the example below). The process works okay, excepting that I cannot figure out how to detect errors in the transformation process.
    I would like to achieve the same result for the pipeline process as I would for a single transformation using javax.xml.transform.Transformer.setErrorListener. The example below demonstrates how the call to javax.xml.transform.Transformer.setErrorListener does not generate the same result when using org.xml.sax.XMLFilter as it does when using a single transformation.
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;
    import javax.xml.parsers.SAXParserFactory;
    import org.xml.sax.SAXException;
    import org.xml.sax.InputSource;
    import org.xml.sax.XMLReader;
    import org.xml.sax.XMLFilter;
    import javax.xml.transform.ErrorListener;
    import javax.xml.transform.Source;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerException;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.TransformerConfigurationException;
    import javax.xml.transform.sax.SAXTransformerFactory;
    import javax.xml.transform.sax.SAXSource;
    import javax.xml.transform.stream.StreamSource;
    import javax.xml.transform.stream.StreamResult;
    import java.io.*;
    public class FilterChain {
        static private final String newline = System.getProperty("line.separator");
         public static void main(String argv[]) {
              System.out.println("Testing pipeline transform");
              testPipelineTransform();
              System.out.println("Testing single transform");
              testXsltSingleTransform();
         } // main
         static private void testPipelineTransform() {
              try {
                   // Set up the input stream
                   BufferedInputStream bis = new BufferedInputStream(
                             new ByteArrayInputStream(getExample().getBytes()));
                   InputSource input = new InputSource(bis);
                   // Set up to read the input file
                   SAXParserFactory spf = SAXParserFactory.newInstance();
                   SAXParser parser = spf.newSAXParser();
                   XMLReader reader = parser.getXMLReader();
                   // Create the filters
                   SAXTransformerFactory stf = (SAXTransformerFactory) TransformerFactory
                             .newInstance();
                   XMLFilter filter1 = stf.newXMLFilter(new StreamSource(new StringReader(getStylesheet1())));
                   XMLFilter filter2 = stf.newXMLFilter(new StreamSource(new StringReader(getStylesheet2())));
                   // Wire the output of the reader to filter1
                   // and the output of filter1 to filter2
                   filter1.setParent(reader);
                   filter2.setParent(filter1);
                   // Set up the output stream
                   StreamResult result = new StreamResult(System.out);
                   // Set up the transformer to process the SAX events generated
                   // by the last filter in the chain
                   Transformer transformer = stf.newTransformer();
                   transformer.setErrorListener(new ErrorListener() {
                        public void error(TransformerException te)
                                  throws TransformerException {
                             System.out.println("Transform generated Transform Error");
                             System.out.println(te.getMessage());
                        public void fatalError(TransformerException te)
                                  throws TransformerException {
                             System.out
                                       .println("Transform generated Transform Fatal Error");
                             System.out.println(te.getMessage());
                        public void warning(TransformerException te)
                                  throws TransformerException {
                             System.out.println("Transform generated Transform Warning");
                             System.out.println(te.getMessage());
                   SAXSource transformSource = new SAXSource(filter2, input);
                   transformer.transform(transformSource, result);
              } catch (TransformerConfigurationException tce) {
                   // Error generated by the parser
                   System.out.println("\n** Transformer Factory error");
                   System.out.println("   " + tce.getMessage());
                   // Use the contained exception, if any
                   Throwable x = tce;
                   if (tce.getException() != null)
                        x = tce.getException();
                   x.printStackTrace();
              } catch (TransformerException te) {
                   // Error generated by the parser
                   System.out.println("\n** Transformation error");
                   System.out.println("   " + te.getMessage());
                   // Use the contained exception, if any
                   Throwable x = te;
                   if (te.getException() != null)
                        x = te.getException();
                   x.printStackTrace();
              } catch (SAXException sxe) {
                   // Error generated by this application
                   // (or a parser-initialization error)
                   Exception x = sxe;
                   if (sxe.getException() != null)
                        x = sxe.getException();
                   x.printStackTrace();
              } catch (ParserConfigurationException pce) {
                   // Parser with specified options can't be built
                   pce.printStackTrace();
         static private void testXsltSingleTransform() {
              try {
                   BufferedInputStream bis = new BufferedInputStream(
                             new ByteArrayInputStream(getExample().getBytes()));
                   // Set up the output stream
                   StreamResult result = new StreamResult(System.out);
                   InputSource input = new InputSource(bis);
                   TransformerFactory factory = TransformerFactory.newInstance();
                   Source source = new StreamSource(new StringReader(getStylesheet2()));
                   Transformer stylesheet = factory.newTransformer(source);
                   stylesheet.setErrorListener(new ErrorListener() {
                        public void error(TransformerException te)
                                  throws TransformerException {
                             System.out.println("Transform generated Transform Error");
                             System.out.println(te.getMessage());
                        public void fatalError(TransformerException te)
                                  throws TransformerException {
                             System.out
                                       .println("Transform generated Transform Fatal Error");
                             System.out.println(te.getMessage());
                        public void warning(TransformerException te)
                                  throws TransformerException {
                             System.out.println("Transform generated Transform Warning");
                             System.out.println(te.getMessage());
                   SAXSource transformSource = new SAXSource(input);
                   stylesheet.transform(transformSource, result);
              } catch (Exception exc) {
                   exc.printStackTrace();
         private static String getStylesheet1() {
              return
                     "<?xml version='1.0' encoding='ISO-8859-1'?>" + newline
                   + "<xsl:stylesheet" + newline
                   + "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'" + newline
                   + "version='1.0'>" + newline
                   + "<xsl:output method='xml'/>" + newline
                   + "<xsl:template match='/'>" + newline
                   + "<DontCareAboutContent></DontCareAboutContent>" + newline
                   + "</xsl:template>" + newline
                   + "</xsl:stylesheet>" + newline;
         private static String getStylesheet2() {
              return
                     "<?xml version='1.0' encoding='ISO-8859-1'?>" + newline
                   + "<xsl:stylesheet" + newline
                   + "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'" + newline
                   + "version='1.0'>" + newline
                   + "<xsl:output method='html'/>" + newline
                   + "<xsl:template match='/'>" + newline
                  + "<html><body>" + newline
                 + "<xsl:message>" + newline
                 + "Error Message for the xslt processor" + newline
                 + "</xsl:message>" + newline
                 + "Dont care about the xslt content," + newline
                 + "The only significant part is the xsl:message element" + newline
                 + "which results in a error to be handled by the xslt" + newline
                 + "processor" + newline
                   + "</body></html>" + newline
                   + "</xsl:template>" + newline
                   + "</xsl:stylesheet>" + newline;
         private static String getExample() {
              return
                     "<?xml version='1.0' encoding='ISO-8859-1'?>" + newline
                   + "<DontCareAboutContent>" + newline
                   + "</DontCareAboutContent>" + newline;
    }

    I made the following change which solves the problem but the sollution is tightly coupled to Xalan. If anyone has any ideas, I would still like to find a way to achieve the desired result using JAXP API's.
                   XMLFilter filter1 = stf.newXMLFilter(new StreamSource(new StringReader(getStylesheet1())));
                   if (filter1 instanceof org.apache.xalan.transformer.TrAXFilter) {
                        ((org.apache.xalan.transformer.TrAXFilter)filter1).getTransformer().setErrorListener(...);
    ...

Maybe you are looking for