Esempio n. 1
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);
  }
 public TemplateSequenceModel getChildNodes() {
   if (regulatedChildBuffer != null) {
     final SimpleSequence seq = new SimpleSequence(regulatedChildCount);
     for (int i = 0; i < regulatedChildCount; i++) {
       seq.add(regulatedChildBuffer[i]);
     }
     return seq;
   }
   SimpleSequence result = new SimpleSequence(1);
   if (nestedBlock != null) {
     result.add(nestedBlock);
   }
   return result;
 }
Esempio n. 3
0
 public static String getMessage(String messageName, SimpleSequence params) {
   try {
     return getMessage(messageName, params.toList().toArray());
   } catch (Exception e) {
     throw new ForumException(e);
   }
 }
Esempio n. 4
0
 /** Converts a FreeMarker {@link SimpleSequence} to a {@link Set}. */
 public static Set<String> simpleSequenceToSet(SimpleSequence simpleSequence) {
   Set<String> result = new HashSet<>();
   for (int i = 0; i < simpleSequence.size(); i++) {
     try {
       Object sequenceEntry = simpleSequence.get(i);
       if (sequenceEntry instanceof SimpleScalar) {
         result.add(((SimpleScalar) sequenceEntry).getAsString());
       } else {
         result.add(simpleSequence.get(i).toString());
       }
     } catch (Exception e) {
       throw new RuntimeException(e);
     }
   }
   return result;
 }