Пример #1
0
 void accept(Environment env) throws TemplateException, IOException {
   String templateNameString = templateName.getStringValue(env);
   if (templateNameString == null) {
     String msg =
         "Error " + getStartLocation() + "The expression " + templateName + " is undefined.";
     throw new InvalidReferenceException(msg, env);
   }
   Template importedTemplate;
   try {
     if (!env.isClassicCompatible()) {
       if (templateNameString.indexOf("://") > 0) {;
       } else if (templateNameString.length() > 0 && templateNameString.charAt(0) == '/') {
         int protIndex = templatePath.indexOf("://");
         if (protIndex > 0) {
           templateNameString = templatePath.substring(0, protIndex + 2) + templateNameString;
         } else {
           templateNameString = templateNameString.substring(1);
         }
       } else {
         templateNameString = templatePath + templateNameString;
       }
     }
     importedTemplate = env.getTemplateForImporting(templateNameString);
   } catch (ParseException pe) {
     String msg = "Error parsing imported template " + templateNameString;
     throw new TemplateException(msg, pe, env);
   } catch (IOException ioe) {
     String msg = "Error reading imported file " + templateNameString;
     throw new TemplateException(msg, ioe, env);
   }
   env.importLib(importedTemplate, namespace);
 }
Пример #2
0
  void accept(Environment env) throws IOException, TemplateException {
    TemplateModel node = targetNode == null ? null : targetNode.getAsTemplateModel(env);
    TemplateModel nss = namespaces == null ? null : namespaces.getAsTemplateModel(env);
    if (namespaces instanceof StringLiteral) {
      nss = env.importLib(((TemplateScalarModel) nss).getAsString(), null);
    } else if (namespaces instanceof ListLiteral) {
      nss = ((ListLiteral) namespaces).evaluateStringsToNamespaces(env);
    }
    if (node != null && !(node instanceof TemplateNodeModel)) {
      throw new TemplateException(
          "Expecting an XML node here, for expression: "
              + targetNode
              + ", found a: "
              + node.getClass().getName(),
          env);
    }
    if (nss != null) {
      if (nss instanceof TemplateHashModel) {
        SimpleSequence ss = new SimpleSequence(1);
        ss.add(nss);
        nss = ss;
      } else if (!(nss instanceof TemplateSequenceModel)) {
        throw new TemplateException("Expecting a sequence of namespaces after 'using'", env);
      }
    }

    env.recurse((TemplateNodeModel) node, (TemplateSequenceModel) nss);
  }