Package org.eclipse.osgi.framework.internal.core

Examples of org.eclipse.osgi.framework.internal.core.Tokenizer


   */
  public static ManifestElement[] parseHeader(String header, String value) throws BundleException {
    if (value == null)
      return (null);
    ArrayList headerElements = new ArrayList(10);
    Tokenizer tokenizer = new Tokenizer(value);
    parseloop: while (true) {
      String next = tokenizer.getString(";,"); //$NON-NLS-1$
      if (next == null)
        throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR);
      ArrayList headerValues = new ArrayList();
      StringBuffer headerValue = new StringBuffer(next);
      headerValues.add(next);

      if (Debug.DEBUG && Debug.DEBUG_MANIFEST)
        Debug.print("parseHeader: " + next); //$NON-NLS-1$
      boolean directive = false;
      char c = tokenizer.getChar();
      // Header values may be a list of ';' separated values.  Just append them all into one value until the first '=' or ','
      while (c == ';') {
        next = tokenizer.getString(";,=:"); //$NON-NLS-1$
        if (next == null)
          throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR);
        c = tokenizer.getChar();
        while (c == ':') { // may not really be a :=
          c = tokenizer.getChar();
          if (c != '=') {
            String restOfNext = tokenizer.getToken(";,=:"); //$NON-NLS-1$
            if (restOfNext == null)
              throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR);
            next += ":" + c + restOfNext; //$NON-NLS-1$
            c = tokenizer.getChar();
          } else
            directive = true;
        }
        if (c == ';' || c == ',' || c == '\0') /* more */{
          headerValues.add(next);
          headerValue.append(";").append(next); //$NON-NLS-1$
          if (Debug.DEBUG && Debug.DEBUG_MANIFEST)
            Debug.print(";" + next); //$NON-NLS-1$
        }
      }
      // found the header value create a manifestElement for it.
      ManifestElement manifestElement = new ManifestElement();
      manifestElement.value = headerValue.toString();
      manifestElement.valueComponents = (String[]) headerValues.toArray(new String[headerValues.size()]);

      // now add any attributes/directives for the manifestElement.
      while (c == '=' || c == ':') {
        while (c == ':') { // may not really be a :=
          c = tokenizer.getChar();
          if (c != '=') {
            String restOfNext = tokenizer.getToken("=:"); //$NON-NLS-1$
            if (restOfNext == null)
              throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR);
            next += ":" + c + restOfNext; //$NON-NLS-1$
            c = tokenizer.getChar();
          } else
            directive = true;
        }
        String val = tokenizer.getString(";,"); //$NON-NLS-1$
        if (val == null)
          throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR);

        if (Debug.DEBUG && Debug.DEBUG_MANIFEST)
          Debug.print(";" + next + "=" + val); //$NON-NLS-1$ //$NON-NLS-2$
        try {
          if (directive)
            manifestElement.addDirective(next, val);
          else
            manifestElement.addAttribute(next, val);
          directive = false;
        } catch (Exception e) {
          throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR, e);
        }
        c = tokenizer.getChar();
        if (c == ';') /* more */{
          next = tokenizer.getToken("=:"); //$NON-NLS-1$
          if (next == null)
            throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR);
          c = tokenizer.getChar();
        }
      }
      headerElements.add(manifestElement);
      if (Debug.DEBUG && Debug.DEBUG_MANIFEST)
        Debug.println(""); //$NON-NLS-1$
View Full Code Here


   */
  public static ManifestElement[] parseHeader(String header, String value) throws BundleException {
    if (value == null)
      return (null);
    List<ManifestElement> headerElements = new ArrayList<ManifestElement>(10);
    Tokenizer tokenizer = new Tokenizer(value);
    parseloop: while (true) {
      String next = tokenizer.getString(";,"); //$NON-NLS-1$
      if (next == null)
        throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR);
      List<String> headerValues = new ArrayList<String>();
      StringBuffer headerValue = new StringBuffer(next);
      headerValues.add(next);

      if (Debug.DEBUG_MANIFEST)
        Debug.print("parseHeader: " + next); //$NON-NLS-1$
      boolean directive = false;
      char c = tokenizer.getChar();
      // Header values may be a list of ';' separated values.  Just append them all into one value until the first '=' or ','
      while (c == ';') {
        next = tokenizer.getString(";,=:"); //$NON-NLS-1$
        if (next == null)
          throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR);
        c = tokenizer.getChar();
        while (c == ':') { // may not really be a :=
          c = tokenizer.getChar();
          if (c != '=') {
            String restOfNext = tokenizer.getToken(";,=:"); //$NON-NLS-1$
            if (restOfNext == null)
              throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR);
            next += ":" + c + restOfNext; //$NON-NLS-1$
            c = tokenizer.getChar();
          } else
            directive = true;
        }
        if (c == ';' || c == ',' || c == '\0') /* more */{
          headerValues.add(next);
          headerValue.append(";").append(next); //$NON-NLS-1$
          if (Debug.DEBUG_MANIFEST)
            Debug.print(";" + next); //$NON-NLS-1$
        }
      }
      // found the header value create a manifestElement for it.
      ManifestElement manifestElement = new ManifestElement(headerValue.toString(), headerValues.toArray(new String[headerValues.size()]));

      // now add any attributes/directives for the manifestElement.
      while (c == '=' || c == ':') {
        while (c == ':') { // may not really be a :=
          c = tokenizer.getChar();
          if (c != '=') {
            String restOfNext = tokenizer.getToken("=:"); //$NON-NLS-1$
            if (restOfNext == null)
              throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value), BundleException.MANIFEST_ERROR);
            next += ":" + c + restOfNext; //$NON-NLS-1$
            c = tokenizer.getChar();
          } else
            directive = true;
        }
        // determine if the attribute is the form attr:List<type>
        String preserveEscapes = null;
        if (!directive && next.indexOf("List") > 0) { //$NON-NLS-1$
          Tokenizer listTokenizer = new Tokenizer(next);
          String attrKey = listTokenizer.getToken(":"); //$NON-NLS-1$
          if (attrKey != null && listTokenizer.getChar() == ':' && "List".equals(listTokenizer.getToken("<"))) { //$NON-NLS-1$//$NON-NLS-2$
            // we assume we must preserve escapes for , and "
            preserveEscapes = "\\,"; //$NON-NLS-1$
          }
        }
        String val = tokenizer.getString(";,", preserveEscapes); //$NON-NLS-1$
View Full Code Here

   */
  public static ManifestElement[] parseHeader(String header, String value) throws BundleException {
    if (value == null)
      return (null);
    ArrayList headerElements = new ArrayList(10);
    Tokenizer tokenizer = new Tokenizer(value);
    parseloop: while (true) {
      String next = tokenizer.getString(";,"); //$NON-NLS-1$
      if (next == null)
        throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value));
      ArrayList headerValues = new ArrayList();
      StringBuffer headerValue = new StringBuffer(next);
      headerValues.add(next);

      if (Debug.DEBUG && Debug.DEBUG_MANIFEST)
        Debug.print("paserHeader: " + next); //$NON-NLS-1$
      boolean directive = false;
      char c = tokenizer.getChar();
      // Header values may be a list of ';' separated values.  Just append them all into one value until the first '=' or ','
      while (c == ';') {
        next = tokenizer.getString(";,=:"); //$NON-NLS-1$
        if (next == null)
          throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value));
        c = tokenizer.getChar();
        while (c == ':') { // may not really be a :=
          c = tokenizer.getChar();
          if (c != '=') {
            String restOfNext = tokenizer.getToken(";,=:"); //$NON-NLS-1$
            if (restOfNext == null)
              throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value));
            next += ":" + c + restOfNext; //$NON-NLS-1$
            c = tokenizer.getChar();
          } else
            directive = true;
        }
        if (c == ';' || c == '\0') /* more */{
          headerValues.add(next);
          headerValue.append(";").append(next); //$NON-NLS-1$
          if (Debug.DEBUG && Debug.DEBUG_MANIFEST)
            Debug.print(";" + next); //$NON-NLS-1$
        }
      }
      // found the header value create a manifestElement for it.
      ManifestElement manifestElement = new ManifestElement();
      manifestElement.value = headerValue.toString();
      manifestElement.valueComponents = (String[]) headerValues.toArray(new String[headerValues.size()]);

      // now add any attributes/directives for the manifestElement.
      while (c == '=' || c == ':') {
        while (c == ':') { // may not really be a :=
          c = tokenizer.getChar();
          if (c != '=') {
            String restOfNext = tokenizer.getToken("=:"); //$NON-NLS-1$
            if (restOfNext == null)
              throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value));
            next += ":" + c + restOfNext; //$NON-NLS-1$
            c = tokenizer.getChar();
          } else
            directive = true;
        }
        String val = tokenizer.getString(";,"); //$NON-NLS-1$
        if (val == null)
          throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value));

        if (Debug.DEBUG && Debug.DEBUG_MANIFEST)
          Debug.print(";" + next + "=" + val); //$NON-NLS-1$ //$NON-NLS-2$
        try {
          if (directive)
            manifestElement.addDirective(next, val);
          else
            manifestElement.addAttribute(next, val);
          directive = false;
        } catch (Exception e) {
          throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value));
        }
        c = tokenizer.getChar();
        if (c == ';') /* more */{
          next = tokenizer.getToken("=:"); //$NON-NLS-1$
          if (next == null)
            throw new BundleException(NLS.bind(Msg.MANIFEST_INVALID_HEADER_EXCEPTION, header, value));
          c = tokenizer.getChar();
        }
      }
      headerElements.add(manifestElement);
      if (Debug.DEBUG && Debug.DEBUG_MANIFEST)
        Debug.println(""); //$NON-NLS-1$
View Full Code Here

TOP

Related Classes of org.eclipse.osgi.framework.internal.core.Tokenizer

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.