10 Replies Latest reply on Aug 20, 2011 4:03 PM by John Hawkinson

    linkXmp.isValid - returns true - when  no Metadata information available?

    wliter


      I'm trying to check if a image has Xmp data and I'm getting  TRUE  in both cases -  the case where there is no data and when there is

       

      the data browser shows it as no Metadata information available when there is no data but true is returned  on linkXmp.isValid

       

      How do you test for this condition?   or is this my misunderstanding or a bug

       

      Thank you for looking at this problem for me

       

       

       

       

          //  isValid    bool     readonly    Returns true if the object specifier resolves to valid objects.
          // linkXmp.isValid   returns true    ... when  no Metadata information available.????
          var myLabel;
          var myLink = myGraphic.itemLink;
          var myStatus = myLink.linkXmp.isValid ;
          $.writeln(myLink.linkXmp.isValid );
          
      
        • 1. Re: linkXmp.isValid - returns true - when  no Metadata information available?
          John Hawkinson Level 5
          How do you test for this condition?   or is this my misunderstanding or a bug

          .isValid is really just telling you that you have a valid specifier. I.e. links[2].isValid would be false if you only had 1 link.

          You'll need to consult some field of the metadata structure, perhaps .format or .keywords. (Well, that's speculation.)

          • 2. Re: linkXmp.isValid - returns true - when  no Metadata information available?
            wliter Level 1

            8-20-2011 2-27-18 AM.jpg

             

            Thank you for your response.

             

            See the problem pictured above

             

            The image does not have any metadata and I want to check for that condition

            the object browser shows isValid as No Metadata information avaiable  which should be false but it returns true

            At this point there is no other field of the metadata structure to consult  consult as would be the case it the metadata was there

             

            This leaves me with a problem of how to discriminate what  images have metadata

            .isValid is really not  telling me anything  in this case I would have expected it to return false

            Don't know if this is a bug  but these same condtions are in CS4 and CS5.5

            • 3. Re: linkXmp.isValid - returns true - when  no Metadata information available?
              John Hawkinson Level 5

              Apparently I was unclear. It is not a bug.  Effectively all that

              .isValid tells you is whether the parent object exists, i.e. that

              you have link data. It gives you no information about the metadata.

               

              I think you will find the Data Browser is very touchy and if you actuall evaluate the .isValid property, then you will get a different answer.

               

              It really isn't telling you anything. Try it on every other object in

              the DOM, it behaves the same way. It is merely a test of the

              legitimacy of the specifier.

               

              You should try what I said in post #1, above.

              • 4. Re: linkXmp.isValid - returns true - when  no Metadata information available?
                wliter Level 1

                Thank you for your response and help but I'm still at a loss.

                 

                I think that the greater issue here is:

                • how to get the  metadata status of the image first to see if it exists
                • and if so validate that it has the fields   ie description and copyright
                  1. on images that have metadata there is no problem
                  2. but those that don't  there is this issue

                 

                As you suggested - I've picked the element of concern description in this case

                 

                var myLink = myGraphic.itemLink;
                var myStatus = myLink.linkXmp.description ;
                $.writeln(myLink.linkXmp.description );
                    
                

                 

                which results in:

                8-20-2011 10-49-16 AM.jpg

                and leaves me at a loss to solve the problem

                 

                or have I missed the point completely

                • 5. Re: linkXmp.isValid - returns true - when  no Metadata information available?
                  Ed Sinclair

                  I remember that accessing metadata properties via the the properties property (if you see what I mean) returns undefined if the property does not exist rather than giving an error. So you could use this style of coding:

                   

                  var myLink = myGraphic.itemLink;

                   

                  var myStatus = myLink.linkXmp.properties.description;

                   

                  if(myStatus != undefined){

                   

                      $.writeln(myLink.linkXmp.properties.description);

                   

                  }else{

                   

                       $.writeln("Description must be missing.");

                   

                  }
                  • 6. Re: linkXmp.isValid - returns true - when  no Metadata information available?
                    wliter Level 1

                    Thank you for your response

                     

                    The problem is a a higher level

                     

                    I want to check if the object [object Link]  myLink.isValid  = is true ( no problem here )

                    but

                    the object  [object LinkMetadata]   myLink.linkXmp.isValid returns true  even when it is clear that the object browser  shows that  No Metadata information available.

                     

                    The problem is not that I'm checking for myLink.linkXmp.properties.description;

                    which will return undefined  if it is empty and only if object LinkMetadata is also valid

                    • 7. Re: linkXmp.isValid - returns true - when  no Metadata information available?
                      John Hawkinson Level 5

                      OK, I actually tested this, rather than just writing.

                      I see what you mean about the error, it looks like you're going to have to catch the exception.

                       

                      Once again, I want to stress: You cannot trust the Data Browser for non-Javascript objects. When looking at InDesign DOM objects, the Data Browser may give you incomplete information before those objects are accessed by Javascript.

                       

                      Anyhow, it looks like you need to do something like:

                       

                      var myLink, temp, hasXmp = false;
                      
                      try {
                        temp = myLink.linkXmp.description;
                        hasXmp = true;
                      } catch (e) {
                        if (e.message !== "No Metadata information available.") {
                          throw(e);
                        }
                      }
                      

                       

                      Ugly, but gets the job done.

                      1 person found this helpful
                      • 8. Re: linkXmp.isValid - returns true - when  no Metadata information available?
                        John Hawkinson Level 5

                        Whoops, I'm sorry, that's not properly localized.

                        Instead of

                        if (e.message !== "No Metadata information available.") {

                        please use

                        if (e.message !== app.translateKeyString(
                            "$ID/NoMetaDataAvailableError"))
                        {
                        

                         

                        (you can find the $ID/ strings by judicious use of app.findKeyStrings()).

                        • 9. Re: linkXmp.isValid - returns true - when  no Metadata information available?
                          wliter Level 1

                          Thank you for taking the time to help me with this problem and to get a better understanding of the complexities

                           

                          var myLink = myGraphic.itemLink;   

                          therefor  myLink Should not be set to false
                          • 10. Re: linkXmp.isValid - returns true - when  no Metadata information available?
                            John Hawkinson Level 5

                            You're welcome. Sorry about that.

                             

                            Please note that the syntax:

                             

                            var myLink, temp, hasXmp = false;

                            Does not set myLink to false. It only sets hasXmp to false. Rather, it declares myLink as a variable. That's probably unnecessary since it is defined elsewhere, but one is in the habit of making sure to declare all variables in Javascript, because if you write a program like this:

                             

                            function pizza(topping) {
                              var a, b;
                              a = topping+" cheese";
                              b = a+" pepperoni";
                              c = b+" anchovie";
                              alert(c);
                            }
                            
                            pizza("pizza");
                            

                             


                            Then c will now be a global variable, because there was no declaration of it, and Javascript has a very very bad language design defect that causes undeclared variables to be treated as global.

                            1 person found this helpful