Examples of ResourceEntry


Examples of com.google.gwt.i18n.rebind.AbstractResource.ResourceEntry

  @Override
  public void createMethodFor(TreeLogger logger, JMethod m, String key,
      ResourceList resourceList, GwtLocale locale)
      throws UnableToCompleteException {
    ResourceEntry resourceEntry = resourceList.getEntry(key);
    if (resourceEntry == null) {
      throw new MissingResourceException(key, resourceList);
    }
    JParameter[] params = m.getParameters();
    boolean seenPluralCount = false;
    boolean seenSelect = false;

    int numParams = params.length;
    int lastPluralArgNumber = -1;
    List<AlternateFormSelector> selectors = new ArrayList<AlternateFormSelector>();
    // See if any parameter is tagged as a PluralCount or Select parameter.
    for (int i = 0; i < numParams; ++i) {
      PluralCount pluralCount = params[i].getAnnotation(PluralCount.class);
      Select select = params[i].getAnnotation(Select.class);
      if (pluralCount != null && select != null) {
        throw error(logger, params[i].getName() + " cannot be both @PluralCount"
            + " and @Select");
      }
      AlternateFormSelector selector = null;
      if (select != null) {
        selector = new GenericSelector(logger, m, i, params);
        seenSelect = true;
      } else if (pluralCount != null) {
        PluralFormSelector pluralSelector = new PluralFormSelector(logger, m, i,
            params, locale);
        selector = pluralSelector;
        if (!seenPluralCount) {
          // TODO(jat): what if we have different plural rules on the different
          // forms?
          resourceList.setPluralForms(key, pluralSelector.getPluralForms());
        }
        seenPluralCount = true;
        lastPluralArgNumber = i;
      }
      if (selector != null) {
        selectors.add(selector);
      }
    }

    boolean[] seenFlags = new boolean[numParams];
    final Parameters paramsAccessor = new ParametersImpl(params, seenFlags);
    boolean isSafeHtml = m.getReturnType().getQualifiedSourceName().equals(
        SAFE_HTML_FQCN);

    String template = resourceEntry.getForm(null);
    if (template == null) {
      logger.log(TreeLogger.ERROR,"No default form for method " + m.getName()
          + "' in " + m.getEnclosingType() + " for locale " + locale, null);
      throw new UnableToCompleteException();
    }

    // Generate code to format any lists
    // TODO(jat): handle messages with different list formats in alternate forms
    try {
      for (TemplateChunk chunk : MessageFormatParser.parse(template)) {
        if (chunk instanceof ArgumentChunk) {
          ArgumentChunk argChunk = (ArgumentChunk) chunk;
          if (argChunk.isList()) {
            ListAccessor listAccessor = null;
            int listArgNum = argChunk.getArgumentNumber();
            JType listType = params[listArgNum].getType();
            JClassType classType = listType.isInterface();
            JType elemType = null;
            if (classType != null) {
              if ("java.util.List".equals(
                  classType.getErasedType().getQualifiedSourceName())) {
                listAccessor = new ListAccessorList(listArgNum);
              } else {
                logger.log(TreeLogger.ERROR, "Parameters formatted as lists "
                    + "must be declared as java.util.List or arrays in "
                    + m.getEnclosingType().getSimpleSourceName() + "."
                    + m.getName());
                throw new UnableToCompleteException();
              }
              JParameterizedType paramType = classType.isParameterized();
              if (paramType != null) {
                elemType = paramType.getTypeArgs()[0];
              } else {
                elemType = classType.getOracle().getJavaLangObject();
              }
            } else {
              JArrayType arrayType = listType.isArray();
              if (arrayType != null) {
                elemType = arrayType.getComponentType();
                listAccessor = new ListAccessorArray(listArgNum);
              }
            }
            generateListFormattingCode(logger, locale, argChunk,
                elemType, isSafeHtml, listAccessor, paramsAccessor);
          }
        }
      }
    } catch (ParseException pe) {
      throw error(logger, "Error parsing '" + template + "'", pe);
    }

    if (!seenPluralCount && !seenSelect
        && (m.getAnnotation(AlternateMessage.class) != null
        || m.getAnnotation(PluralText.class) != null)) {
      logger.log(TreeLogger.WARN, "Unused @AlternateMessage or @PluralText on "
          + m.getEnclosingType().getSimpleSourceName() + "." + m.getName()
          + "; did you intend to mark a @Select or @PluralCount parameter?",
          null);
    }
    Collection<String> resourceForms = resourceEntry.getForms();
    if (seenPluralCount || seenSelect) {
      paramsAccessor.enablePluralOffsets();
      writer.println(m.getReturnType().getParameterizedQualifiedSourceName()
          + " returnVal = null;");
      for (AlternateFormSelector selector : selectors) {
View Full Code Here

Examples of com.google.gwt.i18n.rebind.AbstractResource.ResourceEntry

  @Override
  public void createMethodFor(TreeLogger logger, JMethod m, String key,
      ResourceList resourceList, GwtLocale locale)
      throws UnableToCompleteException {
    ResourceEntry resourceEntry = resourceList.getEntry(key);
    if (resourceEntry == null) {
      throw new MissingResourceException(key, resourceList);
    }
    JParameter[] params = m.getParameters();
    boolean seenPluralCount = false;
    boolean seenSelect = false;

    int numParams = params.length;
    List<AlternateFormSelector> selectors = new ArrayList<AlternateFormSelector>();
    // See if any parameter is tagged as a PluralCount or Select parameter.
    for (int i = 0; i < numParams; ++i) {
      PluralCount pluralCount = params[i].getAnnotation(PluralCount.class);
      Select select = params[i].getAnnotation(Select.class);
      if (pluralCount != null && select != null) {
        throw error(logger, params[i].getName() + " cannot be both @PluralCount"
            + " and @Select");
      }
      AlternateFormSelector selector = null;
      if (select != null) {
        selector = new GenericSelector(logger, m, i, params);
        seenSelect = true;
      } else if (pluralCount != null) {
        PluralFormSelector pluralSelector = new PluralFormSelector(logger, m, i,
            params, locale);
        selector = pluralSelector;
        if (!seenPluralCount) {
          // TODO(jat): what if we have different plural rules on the different
          // forms?
          resourceList.setPluralForms(key, pluralSelector.getPluralForms());
        }
        seenPluralCount = true;
      }
      if (selector != null) {
        selectors.add(selector);
      }
    }

    boolean[] seenFlags = new boolean[numParams];
    final Parameters paramsAccessor = new ParametersImpl(params, seenFlags);
    boolean isSafeHtml = m.getReturnType().getQualifiedSourceName().equals(
        SAFE_HTML_FQCN);

    String template = resourceEntry.getForm(null);
    if (template == null) {
      logger.log(TreeLogger.ERROR,"No default form for method " + m.getName()
          + "' in " + m.getEnclosingType() + " for locale " + locale, null);
      throw new UnableToCompleteException();
    }

    // Generate code to format any lists
    // TODO(jat): handle messages with different list formats in alternate forms
    try {
      for (TemplateChunk chunk : MessageFormatParser.parse(template)) {
        if (chunk instanceof ArgumentChunk) {
          ArgumentChunk argChunk = (ArgumentChunk) chunk;
          if (argChunk.isList()) {
            ListAccessor listAccessor = null;
            int listArgNum = argChunk.getArgumentNumber();
            JType listType = params[listArgNum].getType();
            JClassType classType = listType.isInterface();
            JType elemType = null;
            if (classType != null) {
              if ("java.util.List".equals(
                  classType.getErasedType().getQualifiedSourceName())) {
                listAccessor = new ListAccessorList(listArgNum);
              } else {
                logger.log(TreeLogger.ERROR, "Parameters formatted as lists "
                    + "must be declared as java.util.List or arrays in "
                    + m.getEnclosingType().getSimpleSourceName() + "."
                    + m.getName());
                throw new UnableToCompleteException();
              }
              JParameterizedType paramType = classType.isParameterized();
              if (paramType != null) {
                elemType = paramType.getTypeArgs()[0];
              } else {
                elemType = classType.getOracle().getJavaLangObject();
              }
            } else {
              JArrayType arrayType = listType.isArray();
              if (arrayType != null) {
                elemType = arrayType.getComponentType();
                listAccessor = new ListAccessorArray(listArgNum);
              }
            }
            generateListFormattingCode(logger, locale, argChunk,
                elemType, isSafeHtml, listAccessor, paramsAccessor);
          }
        }
      }
    } catch (ParseException pe) {
      throw error(logger, "Error parsing '" + template + "'", pe);
    }

    if (!seenPluralCount && !seenSelect
        && (m.getAnnotation(AlternateMessage.class) != null
        || m.getAnnotation(PluralText.class) != null)) {
      logger.log(TreeLogger.WARN, "Unused @AlternateMessage or @PluralText on "
          + m.getEnclosingType().getSimpleSourceName() + "." + m.getName()
          + "; did you intend to mark a @Select or @PluralCount parameter?",
          null);
    }
    Collection<String> resourceForms = resourceEntry.getForms();
    if (seenPluralCount) {
      paramsAccessor.enablePluralOffsets();
      writer.println(m.getReturnType().getParameterizedQualifiedSourceName()
          + " returnVal = null;");
      for (AlternateFormSelector selector : selectors) {
View Full Code Here

Examples of org.amdatu.web.resourcehandler.ResourceEntry

public class ResourseKeyParserTest extends TestCase {
    public void testAliasOnlyOk() throws Exception {
        ResourceEntryMap entries = getEntries("path");

        List<ResourceEntry> list = entries.getEntry("");
        ResourceEntry item = list.get(0);

        assertEquals("/path", item.getAlias());
        assertPaths(item, "/path");
    }
View Full Code Here

Examples of org.amdatu.web.resourcehandler.ResourceEntry

        ResourceEntryMap entries = getEntries(entryText);

        List<ResourceEntry> list = entries.getEntry("");
        assertEquals(2, list.size());

        ResourceEntry entry;

        entry = list.get(0);
        assertEquals("/alias1", entry.getAlias());
        assertPaths(entry, "/path1", "/path2", "/path4");

        entry = list.get(1);
        assertEquals("/alias2", entry.getAlias());
        assertPaths(entry, "/path3");
    }
View Full Code Here

Examples of org.amdatu.web.resourcehandler.ResourceEntry

    public void testMulipleContextsAndAliassesAndPaths() throws Exception {
        String entryText = "alias1;path1;context1, alias1;/path2;context2, alias2;/path3, alias3;path2;context1, ";
        ResourceEntryMap entries = getEntries(entryText);

        List<ResourceEntry> list;
        ResourceEntry item;

        list = entries.getEntry("context1");
        assertEquals(2, list.size());

        item = list.get(0);
        assertEquals("/alias1", item.getAlias());
        assertPaths(item, "/path1");

        item = list.get(1);
        assertEquals("/alias3", item.getAlias());
        assertPaths(item, "/path2");

        list = entries.getEntry("");
        assertEquals(1, list.size());

        item = list.get(0);
        assertEquals("/alias2", item.getAlias());
        assertPaths(item, "/path3");

        list = entries.getEntry("context2");
        assertEquals(1, list.size());

        item = list.get(0);
        assertEquals("/alias1", item.getAlias());
        assertPaths(item, "/path2");
    }
View Full Code Here

Examples of org.apache.catalina.loader.ResourceEntry

    }

    @Override
    protected ResourceEntry findResourceInternal(String name, String path) {
        initInstrumentor();
        ResourceEntry entry = super.findResourceInternal(name, path);
        if (entry != null && path.endsWith(".class") && entry.binaryContent != null) {
            String className = name.substring(0, name.length() - ".class".length());
            try {
                byte[] res = instrumentor.instrumentClass(className, entry.binaryContent);
                if (res != null)
View Full Code Here

Examples of org.apache.catalina.loader.ResourceEntry

  }


  @Override
  protected ResourceEntry findResourceInternal(String name, String path) {
    ResourceEntry entry = super.findResourceInternal(name, path);
    // Postpone String parsing as much as possible (it is slow).
    if (entry != null && entry.binaryContent != null && path.endsWith(CLASS_SUFFIX)) {
      String className = (name.endsWith(CLASS_SUFFIX) ? name.substring(0, name.length() - CLASS_SUFFIX.length())
          : name);
      byte[] transformed = this.weavingTransformer.transformIfNecessary(className, entry.binaryContent);
View Full Code Here

Examples of org.apache.catalina.loader.ResourceEntry

  }


  @Override
  protected ResourceEntry findResourceInternal(String name, String path) {
    ResourceEntry entry = super.findResourceInternal(name, path);
    // Postpone String parsing as much as possible (it is slow).
    if (entry != null && entry.binaryContent != null && path.endsWith(".class")) {
      byte[] transformed = this.weavingTransformer.transformIfNecessary(name, entry.binaryContent);
      entry.binaryContent = transformed;
    }
View Full Code Here

Examples of org.apache.catalina.loader.ResourceEntry

  }


  @Override
  protected ResourceEntry findResourceInternal(String name, String path) {
    ResourceEntry entry = super.findResourceInternal(name, path);
    // Postpone String parsing as much as possible (it is slow).
    if (entry != null && entry.binaryContent != null && path.endsWith(".class")) {
      byte[] transformed = this.weavingTransformer.transformIfNecessary(name, entry.binaryContent);
      entry.binaryContent = transformed;
    }
View Full Code Here

Examples of org.apache.catalina.loader.ResourceEntry

      url = findResource(name);
      if (url != null)
      {
         if (getAntiJARLocking())
         {
            ResourceEntry entry = (ResourceEntry) this.resourceEntries.get(name);
            try
            {
               String repository = entry.codeBase.toString();
               if ((repository.endsWith(".jar")) && (!(name.endsWith(".class"))))
               {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.