Package com.adobe.xmp

Examples of com.adobe.xmp.XMPException


    {
      // This is an array indexing step. First get the index, then get the node.

      if (!parentNode.getOptions().isArray())
      {
        throw new XMPException("Indexing applied to non-array", XMPError.BADXPATH);
      }

      if (stepKind == XMPPath.ARRAY_INDEX_STEP)
      {
        index = findIndexedItem(parentNode, nextStep.getName(), createNodes);
      }
      else if (stepKind == XMPPath.ARRAY_LAST_STEP)
      {
        index = parentNode.getChildrenLength();
      }
      else if (stepKind == XMPPath.FIELD_SELECTOR_STEP)
      {
        String[] result = Utils.splitNameAndValue(nextStep.getName());
        String fieldName = result[0];
        String fieldValue = result[1];
        index = lookupFieldSelector(parentNode, fieldName, fieldValue);
      }
      else if (stepKind == XMPPath.QUAL_SELECTOR_STEP)
      {
        String[] result = Utils.splitNameAndValue(nextStep.getName());
        String qualName = result[0];
        String qualValue = result[1];
        index = lookupQualSelector(
          parentNode, qualName, qualValue, nextStep.getAliasForm());
      }
      else
      {
        throw new XMPException("Unknown array indexing step in FollowXPathStep",
            XMPError.INTERNALFAILURE);
      }

      if (1 <= index  &&  index <=  parentNode.getChildrenLength())
      {
View Full Code Here


    {
      segment = segment.substring(1, segment.length() - 1);
      index = Integer.parseInt(segment);
      if (index < 1)
      {
        throw new XMPException("Array index must be larger than zero",
            XMPError.BADXPATH);
      }
    }
    catch (NumberFormatException e)
    {
      throw new XMPException("Array index not digits.", XMPError.BADXPATH);
    }
 
    if (createNodes  &&  index == arrayNode.getChildrenLength() + 1)
    {
      // Append a new last + 1 node.
View Full Code Here

    {
      XMPNode currItem = arrayNode.getChild(index);
 
      if (!currItem.getOptions().isStruct())
      {
        throw new XMPException("Field selector must be used on array of struct",
            XMPError.BADXPATH);
      }
 
      for (int f = 1; f <= currItem.getChildrenLength(); f++)
      {
View Full Code Here

  {
    // See if the array has the right form. Allow empty alt arrays,
    // that is what parsing returns.
    if (!arrayNode.getOptions().isArrayAltText())
    {
      throw new XMPException("Localized text array is not alt-text", XMPError.BADXPATH);
    }
    else if (!arrayNode.hasChildren())
    {
      return new Object[] { new Integer(XMPNodeUtils.CLT_NO_VALUES), null };
    }
 
    int foundGenericMatches = 0;
    XMPNode resultNode = null;
    XMPNode xDefault = null;
 
    // Look for the first partial match with the generic language.
    for (Iterator it = arrayNode.iterateChildren(); it.hasNext();)
    {
      XMPNode currItem = (XMPNode) it.next();
 
      // perform some checks on the current item
      if (currItem.getOptions().isCompositeProperty())
      {
        throw new XMPException("Alt-text array item is not simple", XMPError.BADXPATH);
      }
      else if (!currItem.hasQualifier()
          || !XML_LANG.equals(currItem.getQualifier(1).getName()))
      {
        throw new XMPException("Alt-text array item has no language qualifier",
            XMPError.BADXPATH);
      }
 
      String currLang = currItem.getQualifier(1).getValue();
 
View Full Code Here

   */
  static int lookupLanguageItem(XMPNode arrayNode, String language) throws XMPException
  {
    if (!arrayNode.getOptions().isArray())
    {
      throw new XMPException("Language item must be used on array", XMPError.BADXPATH);
    }
 
    for (int index = 1; index <= arrayNode.getChildrenLength(); index++)
    {
      XMPNode child = arrayNode.getChild(index);
View Full Code Here

   */
  public static XMPDateTime parse(String iso8601String, XMPDateTime binValue) throws XMPException
  {
    if (iso8601String == null)
    {
      throw new XMPException("Parameter must not be null", XMPError.BADPARAM);
    }
    else if (iso8601String.length() == 0)
    {
      return binValue;
    }
   
    ParseState input = new ParseState(iso8601String);
    int value;
   
    if (input.ch(0) == '-')
    {
      input.skip();
    }
   
    // Extract the year.
    value = input.gatherInt("Invalid year in date string", 9999);
    if (input.hasNext()  &&  input.ch() != '-')
    {
      throw new XMPException("Invalid date string, after year", XMPError.BADVALUE);
    }

    if (input.ch(0) == '-')
    {
      value = -value;
    }
    binValue.setYear(value);
    if (!input.hasNext())
    {
      return binValue;
    }
    input.skip();
   
   
    // Extract the month.
    value = input.gatherInt("Invalid month in date string", 12);
    if (input.hasNext()  &&  input.ch() != '-')
    {
      throw new XMPException("Invalid date string, after month", XMPError.BADVALUE);
    }
    binValue.setMonth(value);
    if (!input.hasNext())
    {
      return binValue;
    }
    input.skip();

   
    // Extract the day.
    value = input.gatherInt("Invalid day in date string", 31);
    if (input.hasNext()  &&  input.ch() != 'T')
    {
      throw new XMPException("Invalid date string, after day", XMPError.BADVALUE);
    }
    binValue.setDay(value);
    if (!input.hasNext())
    {
      return binValue;
    }
    input.skip();
   
    // Extract the hour.
    value = input.gatherInt("Invalid hour in date string", 23);
    binValue.setHour(value);
    if (!input.hasNext())
    {
      return binValue;
    }
   
    // Extract the minute.
    if (input.ch() == ':')
    { 
      input.skip();
      value = input.gatherInt("Invalid minute in date string", 59);
      if (input.hasNext()  &&
        input.ch() != ':' && input.ch() != 'Z' && input.ch() != '+' && input.ch() != '-')
      {
        throw new XMPException("Invalid date string, after minute", XMPError.BADVALUE);
      }
      binValue.setMinute(value);
    }
   
    if (!input.hasNext())
    {
      return binValue;
    }
    else if (input.hasNext()  &&  input.ch() == ':')
    {
      input.skip();
      value = input.gatherInt("Invalid whole seconds in date string", 59);
      if (input.hasNext()  &&  input.ch() != '.'  &&  input.ch() != 'Z'  &&
        input.ch() != '+' && input.ch() != '-')
      {
        throw new XMPException("Invalid date string, after whole seconds",
            XMPError.BADVALUE);
      }
      binValue.setSecond(value);
      if (input.ch() == '.')
      {
        input.skip();
        int digits = input.pos();
        value = input.gatherInt("Invalid fractional seconds in date string", 999999999);
        if (input.hasNext()  &&
          (input.ch() != 'Z'  &&  input.ch() != '+'  &&  input.ch() != '-'))
        {
          throw new XMPException("Invalid date string, after fractional second",
              XMPError.BADVALUE);
        }
        digits = input.pos() - digits;
        for (; digits > 9; --digits)
        { 
          value = value / 10;
       
        for (; digits < 9; ++digits)
        { 
          value = value * 10;
       
        binValue.setNanoSecond(value);
      }
    }
    else if (input.ch() != 'Z'  &&  input.ch() != '+'  &&  input.ch() != '-')
    {
      throw new XMPException("Invalid date string, after time", XMPError.BADVALUE);
    }

   
    int tzSign = 0;
    int tzHour = 0;
    int tzMinute = 0;
   
    if (!input.hasNext())
    {
      // no Timezone at all
      return binValue;
    }
    else if (input.ch() == 'Z')
    {
      input.skip();
    }
    else if (input.hasNext())
    {
      if (input.ch() == '+')
      {
        tzSign = 1;
      }
      else if (input.ch() == '-')
      {
        tzSign = -1;
      }
      else
      {
        throw new XMPException("Time zone must begin with 'Z', '+', or '-'",
            XMPError.BADVALUE);
      }

      input.skip();
      // Extract the time zone hour.
      tzHour = input.gatherInt("Invalid time zone hour in date string", 23);
      if (input.hasNext())
      {
        if (input.ch() == ':')
        {
          input.skip();
         
          // Extract the time zone minute.
          tzMinute = input.gatherInt("Invalid time zone minute in date string", 59);
       
        else
        {
          throw new XMPException("Invalid date string, after time zone hour",
            XMPError.BADVALUE);
        }
      } 
    }
   
    // create a corresponding TZ and set it time zone
    int offset = (tzHour * 3600 * 1000 + tzMinute * 60 * 1000) * tzSign;  
    binValue.setTimeZone(new SimpleTimeZone(offset, ""));

    if (input.hasNext())
    {
      throw new XMPException(
        "Invalid date string, extra chars at end", XMPError.BADVALUE);
    }
   
    return binValue;
  }
View Full Code Here

        return value;
     
    }
    else
    {
      throw new XMPException(errorMsg, XMPError.BADVALUE);
    }
  }
View Full Code Here

    {
      return "";
    }
    else if (!arrayNode.getOptions().isArray() || arrayNode.getOptions().isArrayAlternate())
    {
      throw new XMPException("Named property must be non-alternate array", XMPError.BADPARAM);
    }

    // Make sure the separator is OK.
    checkSeparator(separator);
    // Make sure the open and close quotes are a legitimate pair.
    char openQuote = quotes.charAt(0);
    char closeQuote = checkQuotes(quotes, openQuote);

    // Build the result, quoting the array items, adding separators.
    // Hurl if any item isn't simple.

    StringBuffer catinatedString = new StringBuffer();

    for (Iterator it = arrayNode.iterateChildren(); it.hasNext();)
    {
      currItem = (XMPNode) it.next();
      if (currItem.getOptions().isCompositeProperty())
      {
        throw new XMPException("Array items must be simple", XMPError.BADPARAM);
      }
      String str = applyQuotes(currItem.getValue(), openQuote, closeQuote, allowCommas);

      catinatedString.append(str);
      if (it.hasNext())
View Full Code Here

  {
    ParameterAsserts.assertSchemaNS(schemaNS);
    ParameterAsserts.assertArrayName(arrayName);
    if (catedStr == null)
    {
      throw new XMPException("Parameter must not be null", XMPError.BADPARAM);
    }
    ParameterAsserts.assertImplementation(xmp);
    XMPMetaImpl xmpImpl = (XMPMetaImpl) xmp;

    // Keep a zero value, has special meaning below.
View Full Code Here

      PropertyOptions arrayOptions, XMPMetaImpl xmp) throws XMPException
  {
    arrayOptions = XMPNodeUtils.verifySetOptions(arrayOptions, null);
    if (!arrayOptions.isOnlyArrayOptions())
    {
      throw new XMPException("Options can only provide array form", XMPError.BADOPTIONS);
    }

    // Find the array node, make sure it is OK. Move the current children
    // aside, to be readded later if kept.
    XMPPath arrayPath = XMPPathParser.expandXPath(schemaNS, arrayName);
    XMPNode arrayNode = XMPNodeUtils.findNode(xmp.getRoot(), arrayPath, false, null);
    if (arrayNode != null)
    {
      // The array exists, make sure the form is compatible. Zero
      // arrayForm means take what exists.
      PropertyOptions arrayForm = arrayNode.getOptions();
      if (!arrayForm.isArray() || arrayForm.isArrayAlternate())
      {
        throw new XMPException("Named property must be non-alternate array",
          XMPError.BADXPATH);
      }
      if (arrayOptions.equalArrayTypes(arrayForm))
      {
        throw new XMPException("Mismatch of specified and existing array form",
            XMPError.BADXPATH); // *** Right error?
      }
    }
    else
    {
      // The array does not exist, try to create it.
      // don't modify the options handed into the method
      arrayNode = XMPNodeUtils.findNode(xmp.getRoot(), arrayPath, true, arrayOptions
          .setArray(true));
      if (arrayNode == null)
      {
        throw new XMPException("Failed to create named array", XMPError.BADXPATH);
      }
    }
    return arrayNode;
  }
View Full Code Here

TOP

Related Classes of com.adobe.xmp.XMPException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.