Exemplo n.º 1
0
 private InfoDirective buildInfoDirective(Element element) {
   if (null == element) {
     return null;
   } else {
     String title = ElementHelper.getAttribute(element, "title");
     Element child = ElementHelper.getChild(element, "description");
     if (null == child) {
       return new InfoDirective(title, null);
     } else {
       String value = ElementHelper.getValue(child);
       String description = trim(value);
       return new InfoDirective(title, description);
     }
   }
 }
Exemplo n.º 2
0
  private ResourceDirective buildResourceDirective(File base, Element element, String path)
      throws Exception {
    Classifier classifier = null;
    final String tag = element.getTagName();
    if (RESOURCE_ELEMENT_NAME.equals(tag)
        || PROJECT_ELEMENT_NAME.equals(tag)
        || MODULE_ELEMENT_NAME.equals(tag)) {
      final String name = ElementHelper.getAttribute(element, "name");
      final String version = ElementHelper.getAttribute(element, "version");
      String basedir = ElementHelper.getAttribute(element, "basedir");
      if (path != null) {
        if (basedir == null) {
          basedir = path;
        } else {
          basedir = path + "/" + basedir;
        }
      }

      if (PROJECT_ELEMENT_NAME.equals(tag)) {
        classifier = Classifier.LOCAL;
        if (null == basedir) {
          basedir = ".";
        }
      } else if (MODULE_ELEMENT_NAME.equals(tag)) {
        if (null != basedir) {
          classifier = Classifier.LOCAL;
        } else {
          classifier = Classifier.EXTERNAL;
        }
      } else {
        classifier = Classifier.EXTERNAL;
      }

      final boolean export = ElementHelper.getBooleanAttribute(element, "export", true);

      final InfoDirective info = buildInfoDirective(ElementHelper.getChild(element, "info"));

      final TypeDirective[] data = buildTypeDirectives(ElementHelper.getChild(element, "types"));

      final DependencyDirective[] dependencies =
          buildDependencyDirectives(ElementHelper.getChild(element, "dependencies"));

      final FilterDirective[] filters =
          buildFilterDirectives(ElementHelper.getChild(element, "filters"));

      final Properties properties = buildProperties(ElementHelper.getChild(element, "properties"));

      if (MODULE_ELEMENT_NAME.equals(tag)) {
        File anchor = getAnchorDirectory(base, basedir);
        ArrayList<ResourceDirective> list = new ArrayList<ResourceDirective>();
        Element[] children = ElementHelper.getChildren(element);
        for (int i = 0; i < children.length; i++) {
          Element child = children[i];
          final String t = child.getTagName();

          if (RESOURCE_ELEMENT_NAME.equals(t)
              || PROJECT_ELEMENT_NAME.equals(t)
              || MODULE_ELEMENT_NAME.equals(t)) {
            ResourceDirective directive = buildResourceDirectiveFromElement(anchor, child, null);
            list.add(directive);
          }
        }

        ResourceDirective[] resources = list.toArray(new ResourceDirective[0]);
        return ModuleDirective.createModuleDirective(
            name,
            version,
            classifier,
            basedir,
            info,
            data,
            dependencies,
            properties,
            filters,
            resources,
            export);
      } else {
        return ResourceDirective.createResourceDirective(
            name,
            version,
            classifier,
            basedir,
            info,
            data,
            dependencies,
            properties,
            filters,
            export);
      }
    } else {
      final String error = "Invalid element name [" + tag + "].";
      throw new DecodingException(error, null, element);
    }
  }