예제 #1
0
  @SuppressWarnings("rawtypes")
  @Override
  protected void readSystemAttributes() throws QuickFixException {
    super.readSystemAttributes();
    builder.setLocalId(getSystemAttributeValue("id"));
    String load = getSystemAttributeValue("load");
    if (!AuraTextUtil.isNullEmptyOrWhitespace(load)) {
      Load loadVal;
      try {
        loadVal = Load.valueOf(load.toUpperCase());
      } catch (IllegalArgumentException e) {
        throw new AuraRuntimeException(
            String.format("Invalid value '%s' specified for 'aura:load' attribute", load),
            getLocation());
      }
      builder.setLoad(loadVal);
      if (loadVal == Load.LAZY || loadVal == Load.EXCLUSIVE) {
        ((BaseComponentDefHandler) getParentHandler()).setRender("client");
      }
    }

    String flavor = getSystemAttributeValue("flavor");
    if (!AuraTextUtil.isNullEmptyOrWhitespace(flavor)) {
      builder.setFlavor(flavor);
    }
  }
예제 #2
0
  @Override
  @SuppressWarnings("unchecked")
  public IncludeDefImpl getElement() throws XMLStreamException, QuickFixException {
    if (parentHandler.getDefDescriptor().getDefType() != DefType.LIBRARY) {
      error("aura:include may only be set in a library.");
    }

    DefDescriptor<LibraryDef> parentDescriptor =
        (DefDescriptor<LibraryDef>) parentHandler.getDefDescriptor();
    builder.setLocation(getLocation());

    String name = getAttributeValue(ATTRIBUTE_NAME);
    if (!AuraTextUtil.isNullEmptyOrWhitespace(name)) {
      builder.setName(name);
    } else {
      error("aura:include must specify a valid library name.");
    }
    if (name.toLowerCase().endsWith(".js")) {
      name = name.substring(0, name.length() - 3);
    }
    builder.setDescriptor(
        DefDescriptorImpl.getInstance(
            String.format("js://%s.%s", parentDescriptor.getNamespace(), name),
            IncludeDef.class,
            parentDescriptor));

    String imports = getAttributeValue(ATTRIBUTE_IMPORTS);
    if (!AuraTextUtil.isNullEmptyOrWhitespace(imports)) {
      builder.setImports(Arrays.asList(imports.split("\\s*\\,\\s*")));
    }

    String exports = getAttributeValue(ATTRIBUTE_EXPORTS);
    if (!AuraTextUtil.isNullEmptyOrWhitespace(exports)) {
      builder.setExports(exports);
    }

    builder.setParentDescriptor(parentDescriptor);

    int next = xmlReader.next();
    if (next != XMLStreamConstants.END_ELEMENT || !TAG.equalsIgnoreCase(getTagName())) {
      error("expected end of %s tag", TAG);
    }

    builder.setOwnHash(source.getHash());

    return builder.build();
  }
예제 #3
0
  @Override
  protected void readAttributes() throws InvalidDefinitionException {
    String componentFilter = getAttributeValue(ATTRIBUTE_COMPONENT);
    if (!AuraTextUtil.isNullEmptyOrWhitespace(componentFilter)) {
      builder.setComponent(componentFilter);
    } else {
      throw new InvalidDefinitionException("Missing required attribute 'component'", getLocation());
    }

    String flavorFilter = getAttributeValue(ATTRIBUTE_DEFAULT);
    if (!AuraTextUtil.isNullEmptyOrWhitespace(flavorFilter)) {
      builder.setFlavor(flavorFilter);
    } else {
      throw new InvalidDefinitionException("Missing required attribute 'default'", getLocation());
    }

    builder.setDescription(getAttributeValue(ATTRIBUTE_DESCRIPTION));
    builder.setParentDescriptor(getParentDefDescriptor());
    builder.setDescriptor(definitionService.getDefDescriptor(flavorFilter, FlavorDefaultDef.class));
  }
예제 #4
0
 @Override
 protected String getAttributeValue(String name) {
   String value = xmlReader.getAttributeValue(null, name);
   if (AuraTextUtil.isNullEmptyOrWhitespace(value)) {
     for (int i = 0; i < xmlReader.getAttributeCount(); i++) {
       if (xmlReader.getAttributeLocalName(i).equalsIgnoreCase(name)) {
         return xmlReader.getAttributeValue(i);
       }
     }
   }
   return value;
 }
예제 #5
0
 @SuppressWarnings("unchecked")
 private Map<String, Object> getConfigMap(HttpServletRequest request) {
   Map<String, Object> configMap = null;
   String config = contextConfig.get(request);
   if (!AuraTextUtil.isNullEmptyOrWhitespace(config)) {
     if (config.startsWith(AuraTextUtil.urlencode("{"))) {
       // Decode encoded context json. Serialized AuraContext json always starts with "{"
       config = AuraTextUtil.urldecode(config);
     }
     configMap = (Map<String, Object>) new JsonReader().read(config);
   }
   return configMap;
 }
예제 #6
0
  protected Map<DefDescriptor<AttributeDef>, AttributeDefRef> getAttributes()
      throws QuickFixException {
    // TODOJT: add varargs "validAttributeNames" to this and validate that
    // any attributes we find are in that list.
    // TODOJT: possibly those arguments are like *Param objects with
    // built-in value validation?
    Map<DefDescriptor<AttributeDef>, AttributeDefRef> attributes = new LinkedHashMap<>();

    for (int i = 0; i < xmlReader.getAttributeCount(); i++) {
      String attName = xmlReader.getAttributeLocalName(i);
      String prefix = xmlReader.getAttributePrefix(i);
      if (!XMLHandler.isSystemPrefixed(attName, prefix)) {
        // W-2316503: remove compatibility code for both SJSXP and Woodstox
        if (!AuraTextUtil.isNullEmptyOrWhitespace(prefix) && !attName.contains(":")) {
          attName = prefix + ":" + attName;
        }
        DefDescriptor<AttributeDef> att =
            DefDescriptorImpl.getInstance(attName, AttributeDef.class);

        String attValue = xmlReader.getAttributeValue(i);
        if (attributes.containsKey(att)) {
          error("Duplicate values for attribute %s on tag %s", att, getTagName());
        }
        TextTokenizer tt = TextTokenizer.tokenize(attValue, getLocation());
        Object value = tt.asValue(getParentHandler());

        AttributeDefRefImpl.Builder atBuilder = new AttributeDefRefImpl.Builder();
        atBuilder.setDescriptor(att);
        atBuilder.setLocation(getLocation());
        atBuilder.setValue(value);
        attributes.put(att, atBuilder.build());
      }
    }

    return attributes;
  }
예제 #7
0
 /**
  * Gets system attribute by prepending system prefix.
  *
  * @param name attribute name
  * @return attribute value
  */
 protected String getSystemAttributeValue(String name) {
   // W-2316503: remove compatibility code for both SJSXP and Woodstox
   String value = getAttributeValue(SYSTEM_TAG_PREFIX + ":" + name);
   if (value != null) {
     // woodstox
     // With IS_NAMESPACE_AWARE disabled, woodstox will not set attribute prefix
     // so we can get the value from entire attribute name
     return value;
   } else {
     // sjsxp
     // defaults to setting attribute prefix regardless of IS_NAMESPACE_AWARE setting
     value = getAttributeValue(name);
     if (!AuraTextUtil.isNullEmptyOrWhitespace(value)) {
       // ensure system prefixed value of attribute ie "id" vs "aura:id"
       for (int i = 0; i < xmlReader.getAttributeCount(); i++) {
         if (xmlReader.getAttributeLocalName(i).equalsIgnoreCase(name)
             && SYSTEM_TAG_PREFIX.equalsIgnoreCase(xmlReader.getAttributePrefix(i))) {
           return xmlReader.getAttributeValue(i);
         }
       }
     }
     return null;
   }
 }
예제 #8
0
  @Override
  @SuppressWarnings("unchecked")
  public IncludeDefRefImpl getElement() throws XMLStreamException, QuickFixException {
    DefDescriptor<LibraryDef> parentDescriptor =
        (DefDescriptor<LibraryDef>) parentHandler.getDefDescriptor();
    if (parentDescriptor.getDefType() != DefType.LIBRARY) {
      throw new InvalidDefinitionException(
          "aura:include may only be set in a library.", getLocation());
    }

    validateAttributes();

    builder.setLocation(getLocation());

    String name = getAttributeValue(ATTRIBUTE_NAME);
    if (AuraTextUtil.isNullEmptyOrWhitespace(name)) {
      throw new InvalidDefinitionException(
          ("aura:include must specify a valid library name."), getLocation());
    }
    builder.setDescriptor(
        SubDefDescriptorImpl.getInstance(name, parentDescriptor, IncludeDefRef.class));
    builder.setIncludeDescriptor(
        DefDescriptorImpl.getInstance(
            String.format("%s.%s", parentDescriptor.getNamespace(), name),
            IncludeDef.class,
            parentDescriptor));

    String importNames = getAttributeValue(ATTRIBUTE_IMPORTS);
    if (!AuraTextUtil.isNullEmptyOrWhitespace(importNames)) {
      List<DefDescriptor<IncludeDef>> imports = Lists.newLinkedList();
      for (String importName : Arrays.asList(importNames.trim().split("\\s*\\,\\s*"))) {
        String[] parts = importName.split(":");
        if (parts.length == 1) { // local import
          imports.add(
              DefDescriptorImpl.getInstance(
                  String.format("%s.%s", parentDescriptor.getNamespace(), importName),
                  IncludeDef.class,
                  parentDescriptor));
        } else if (parts.length == 3) { // external import
          DefDescriptor<LibraryDef> externalLibrary =
              DefDescriptorImpl.getInstance(
                  String.format("%s:%s", parts[0], parts[1]), LibraryDef.class);
          imports.add(
              DefDescriptorImpl.getInstance(
                  String.format("%s.%s", parts[0], parts[2]), IncludeDef.class, externalLibrary));
        } else { // invalid import name
          throw new InvalidDefinitionException(
              String.format("Invalid name in aura:include imports property: %s", importName),
              getLocation());
        }
      }
      builder.setImports(imports);
    }

    String export = getAttributeValue(ATTRIBUTE_EXPORT);
    if (!AuraTextUtil.isNullEmptyOrWhitespace(export)) {
      builder.setExport(export);
    }

    builder.setDescription(getAttributeValue(RootTagHandler.ATTRIBUTE_DESCRIPTION));

    int next = xmlReader.next();
    if (next != XMLStreamConstants.END_ELEMENT || !TAG.equalsIgnoreCase(getTagName())) {
      error("expected end of %s tag", TAG);
    }

    builder.setOwnHash(source.getHash());

    return builder.build();
  }
예제 #9
0
 @Override
 protected void handleChildText() throws XMLStreamException, QuickFixException {
   if (!AuraTextUtil.isNullEmptyOrWhitespace(xmlReader.getText())) {
     error("No literal text allowed in %s tag", TAG);
   }
 }