Package com.adobe.xmp

Examples of com.adobe.xmp.XMPException


      // the named schema might not actually exist. So don't lookup the
      // schema node.

      if (schemaNS == null || schemaNS.length() == 0)
      {
        throw new XMPException("Property name requires schema namespace",
          XMPError.BADPARAM);
      }

      XMPPath expPath = XMPPathParser.expandXPath(schemaNS, propName);
View Full Code Here


      int charKind = classifyCharacter(separator.charAt(i));
      if (charKind == UCK_SEMICOLON)
      {
        if (haveSemicolon)
        {
          throw new XMPException("Separator can have only one semicolon",
            XMPError.BADPARAM);
        }
        haveSemicolon = true;
      }
      else if (charKind != UCK_SPACE)
      {
        throw new XMPException("Separator can have only spaces and one semicolon",
            XMPError.BADPARAM);
      }
    }
    if (!haveSemicolon)
    {
      throw new XMPException("Separator must have one semicolon", XMPError.BADPARAM);
    }
  }
View Full Code Here

    char closeQuote;

    int charKind = classifyCharacter(openQuote);
    if (charKind != UCK_QUOTE)
    {
      throw new XMPException("Invalid quoting character", XMPError.BADPARAM);
    }

    if (quotes.length() == 1)
    {
      closeQuote = openQuote;
    }
    else
    {
      closeQuote = quotes.charAt(1);
      charKind = classifyCharacter(closeQuote);
      if (charKind != UCK_QUOTE)
      {
        throw new XMPException("Invalid quoting character", XMPError.BADPARAM);
      }
    }

    if (closeQuote != getClosingQuote(openQuote))
    {
      throw new XMPException("Mismatched quote pair", XMPError.BADPARAM);
    }
    return closeQuote;
  }
View Full Code Here

    {
      arrayOptions = new PropertyOptions();
    }
    if (!arrayOptions.isOnlyArrayOptions())
    {
      throw new XMPException("Only array form flags allowed for arrayOptions",
          XMPError.BADOPTIONS);
    }

    // Check if array options are set correctly.
    arrayOptions = XMPNodeUtils.verifySetOptions(arrayOptions, null);


    // Locate or create the array. If it already exists, make sure the array
    // form from the options
    // parameter is compatible with the current state.
    XMPPath arrayPath = XMPPathParser.expandXPath(schemaNS, arrayName);


    // Just lookup, don't try to create.
    XMPNode arrayNode = XMPNodeUtils.findNode(tree, arrayPath, false, null);

    if (arrayNode != null)
    {
      // The array exists, make sure the form is compatible. Zero
      // arrayForm means take what exists.
      if (!arrayNode.getOptions().isArray())
      {
        throw new XMPException("The named property is not an array", XMPError.BADXPATH);
      }
      // if (arrayOptions != null && !arrayOptions.equalArrayTypes(arrayNode.getOptions()))
      // {
      // throw new XMPException("Mismatch of existing and specified array form", BADOPTIONS);
      // }
    }
    else
    {
      // The array does not exist, try to create it.
      if (arrayOptions.isArray())
      {
        arrayNode = XMPNodeUtils.findNode(tree, arrayPath, true, arrayOptions);
        if (arrayNode == null)
        {
          throw new XMPException("Failure creating array node", XMPError.BADXPATH);
        }
      }
      else
      {
        // array options missing
        throw new XMPException("Explicit arrayOptions required to create new array",
            XMPError.BADOPTIONS);
      }
    }

    doSetArrayItem(arrayNode, ARRAY_LAST_ITEM, itemValue, itemOptions, true);
View Full Code Here

    {
      return arrayNode.getChildrenLength();
    }
    else
    {
      throw new XMPException("The named property is not an array", XMPError.BADXPATH);
    }
  }
View Full Code Here

        PropertyOptions.ARRAY | PropertyOptions.ARRAY_ORDERED
            | PropertyOptions.ARRAY_ALTERNATE | PropertyOptions.ARRAY_ALT_TEXT));

    if (arrayNode == null)
    {
      throw new XMPException("Failed to find or create array node", XMPError.BADXPATH);
    }
    else if (!arrayNode.getOptions().isArrayAltText())
    {
      if (!arrayNode.hasChildren() && arrayNode.getOptions().isArrayAlternate())
      {
        arrayNode.getOptions().setArrayAltText(true);
      }
      else
      {
        throw new XMPException(
          "Specified property is no alt-text array", XMPError.BADXPATH);
      }
    }

    // Make sure the x-default item, if any, is first.
    boolean haveXDefault = false;
    XMPNode xdItem = null;

    for (Iterator it = arrayNode.iterateChildren(); it.hasNext();)
    {
      XMPNode currItem = (XMPNode) it.next();
      if (!currItem.hasQualifier()
          || !XMPConst.XML_LANG.equals(currItem.getQualifier(1).getName()))
      {
        throw new XMPException("Language qualifier must be first", XMPError.BADXPATH);
      }
      else if (XMPConst.X_DEFAULT.equals(currItem.getQualifier(1).getValue()))
      {
        xdItem = currItem;
        haveXDefault = true;
        break;
      }
    }

    // Moves x-default to the beginning of the array
    if (xdItem != null  &&  arrayNode.getChildrenLength() > 1)
    {
      arrayNode.removeChild(xdItem);
      arrayNode.addChild(1, xdItem);
    }

    // Find the appropriate item.
    // chooseLocalizedText will make sure the array is a language
    // alternative.
    Object[] result = XMPNodeUtils.chooseLocalizedText(arrayNode, genericLang, specificLang);
    int match = ((Integer) result[0]).intValue();
    XMPNode itemNode = (XMPNode) result[1];

    boolean specificXDefault = XMPConst.X_DEFAULT.equals(specificLang);

    switch (match)
    {
    case XMPNodeUtils.CLT_NO_VALUES:

      // Create the array items for the specificLang and x-default, with
      // x-default first.
      XMPNodeUtils.appendLangItem(arrayNode, XMPConst.X_DEFAULT, itemValue);
      haveXDefault = true;
      if (!specificXDefault)
      {
        XMPNodeUtils.appendLangItem(arrayNode, specificLang, itemValue);
      }
      break;

    case XMPNodeUtils.CLT_SPECIFIC_MATCH:

      if (!specificXDefault)
      {
        // Update the specific item, update x-default if it matches the
        // old value.
        if (haveXDefault && xdItem != itemNode && xdItem != null
            && xdItem.getValue().equals(itemNode.getValue()))
        {
          xdItem.setValue(itemValue);
        }
        // ! Do this after the x-default check!
        itemNode.setValue(itemValue);
      }
      else
      {
        // Update all items whose values match the old x-default value.
        assert  haveXDefault  &&  xdItem == itemNode;
        for (Iterator it = arrayNode.iterateChildren(); it.hasNext();)
        {
          XMPNode currItem = (XMPNode) it.next();
          if (currItem == xdItem
              || !currItem.getValue().equals(
                  xdItem != null ? xdItem.getValue() : null))
          {
            continue;
          }
          currItem.setValue(itemValue);
        }
        // And finally do the x-default item.
        if (xdItem != null)
        { 
          xdItem.setValue(itemValue);
       
      }
      break;

    case XMPNodeUtils.CLT_SINGLE_GENERIC:

      // Update the generic item, update x-default if it matches the old
      // value.
      if (haveXDefault && xdItem != itemNode && xdItem != null
          && xdItem.getValue().equals(itemNode.getValue()))
      {
        xdItem.setValue(itemValue);
      }
      itemNode.setValue(itemValue); // ! Do this after
      // the x-default
      // check!
      break;

    case XMPNodeUtils.CLT_MULTIPLE_GENERIC:

      // Create the specific language, ignore x-default.
      XMPNodeUtils.appendLangItem(arrayNode, specificLang, itemValue);
      if (specificXDefault)
      {
        haveXDefault = true;
      }
      break;

    case XMPNodeUtils.CLT_XDEFAULT:

      // Create the specific language, update x-default if it was the only
      // item.
      if (xdItem != null  &&  arrayNode.getChildrenLength() == 1)
      {
        xdItem.setValue(itemValue);
      }
      XMPNodeUtils.appendLangItem(arrayNode, specificLang, itemValue);
      break;

    case XMPNodeUtils.CLT_FIRST_ITEM:

      // Create the specific language, don't add an x-default item.
      XMPNodeUtils.appendLangItem(arrayNode, specificLang, itemValue);
      if (specificXDefault)
      {
        haveXDefault = true;
      }
      break;

    default:
      // does not happen under normal circumstances
      throw new XMPException("Unexpected result from ChooseLocalizedText",
          XMPError.INTERNALFAILURE);

    }

    // Add an x-default at the front if needed.
View Full Code Here

    if (propNode != null)
    {
      if (valueType != VALUE_STRING && propNode.getOptions().isCompositeProperty())
      {
        throw new XMPException("Property must be simple when a value type is requested",
            XMPError.BADXPATH);
      }

      final Object value = evaluateNodeValue(valueType, propNode);
View Full Code Here

    if (propNode != null)
    {
      if (valueType != VALUE_STRING && propNode.getOptions().isCompositeProperty())
      {
        throw new XMPException("Property must be simple when a value type is requested",
            XMPError.BADXPATH);
      }

      return evaluateNodeValue(valueType, propNode);
    }
View Full Code Here

    {
      doSetArrayItem(arrayNode, itemIndex, itemValue, options, false);
    }
    else
    {
      throw new XMPException("Specified array does not exist", XMPError.BADXPATH);
    }
  }
View Full Code Here

    {
      doSetArrayItem(arrayNode, itemIndex, itemValue, options, true);
    }
    else
    {
      throw new XMPException("Specified array does not exist", XMPError.BADXPATH);
    }
  }
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.