void getAsString(Object node, StringWriter sw) throws TemplateModelException {
   try {
     if (node instanceof Element) {
       OUTPUT.output((Element) node, sw);
     } else if (node instanceof Attribute) {
       Attribute attribute = (Attribute) node;
       sw.write(" ");
       sw.write(attribute.getQualifiedName());
       sw.write("=\"");
       sw.write(OUTPUT.escapeAttributeEntities(attribute.getValue()));
       sw.write("\"");
     } else if (node instanceof Text) {
       OUTPUT.output((Text) node, sw);
     } else if (node instanceof Document) {
       OUTPUT.output((Document) node, sw);
     } else if (node instanceof ProcessingInstruction) {
       OUTPUT.output((ProcessingInstruction) node, sw);
     } else if (node instanceof Comment) {
       OUTPUT.output((Comment) node, sw);
     } else if (node instanceof CDATA) {
       OUTPUT.output((CDATA) node, sw);
     } else if (node instanceof DocType) {
       OUTPUT.output((DocType) node, sw);
     } else if (node instanceof EntityRef) {
       OUTPUT.output((EntityRef) node, sw);
     } else {
       throw new TemplateModelException(node.getClass().getName() + " is not a core JDOM class");
     }
   } catch (IOException e) {
     throw new TemplateModelException(e);
   }
 }
예제 #2
0
    /**
     * Constructor of the TCK reporter, writing to the given file.
     *
     * @param file the target file, not null.
     */
    @SuppressWarnings("CallToPrintStackTrace")
    public TCKReporter(File file) {
      try {
        if (!file.exists()) {
          file.createNewFile();
        }
        w = new FileWriter(file);
        w.write(
            "********************************************************************************************\n");
        w.write("**** JSR 354 - Money & Currency, Technical Compatibility Kit, version 1.1\n");
        w.write(
            "********************************************************************************************\n\n");
        w.write("Executed on " + new java.util.Date() + "\n\n");

        // System.out:
        internalBuffer.write(
            "********************************************************************************\n");
        internalBuffer.write(
            "**** JSR 354 - Money & Currency, Technical Compatibility Kit, version 1.1.\n");
        internalBuffer.write(
            "********************************************************************************\n\n");
        internalBuffer.write("Executed on " + new java.util.Date() + "\n\n");
      } catch (IOException e) {
        e.printStackTrace();
        System.exit(-1);
      }
    }
 protected void addFilter(String attributeName, String attributeValue, StringWriter writer) {
   writer.write("(");
   writer.write(attributeName);
   writer.write("=");
   writer.write(attributeValue);
   writer.write(")");
 }
  /**
   * Process an MXMLTextData - this will write a String representation of the tag into the
   * StringWriter passed in. This will strip out any databinding expressions from the String. This
   * will write out only CDATA and TEXT TextDatas Other kinds of text data are not output into the
   * resulting XML object. TODO: databinding - add the databinding expressions as children of the
   * MXMLXMLNode, and also record what the TODO: target expressions for those are (these are the
   * expressions to set the value in the XML object when the TODO: PropertyChange event fires).
   */
  void processNode(MXMLTextData tag, StringWriter sw) {
    switch (tag.getTextType()) {
      case CDATA:
        // For CDATA, just write out the text
        sw.write(tag.getContent());
        break;
      case TEXT:
        {
          IMXMLSingleDataBindingNode db = null;
          if ((db = parseBindingExpression(tag)) != null) {
            //   do databinding stuff:
            //      1.  Walk up parent chain to compute target expression
            //      2.  Parse databinding expression
            //      3.  Save off both those pieces of data for use during codegen

            databindings.add(generateBindingNode(tag, db));
            if (!isOnlyTextChild(tag)) {
              // Write out an empty CDATA section, so the tag will have the right
              // number of text children for the binding to target.
              sw.write("<![CDATA[]]>");
            }
          } else {
            sw.write(replaceBindingEscapes(tag.getContent()));
          }
        }
        break;
        // Everything else gets stripped out
    }
  }
예제 #5
0
  /**
   * Return the text string that represents the current configuration of this object. This will
   * include whatever classes, entities, and relations have been previously instantiated. FIXME:
   * Shouldn't this also include connections???
   *
   * @return A configuration string, or null if no configuration has been used to configure this
   *     object, or null if no configuration string need be used to configure this object.
   */
  public String getConfigureText() {
    try {
      StringWriter stringWriter = new StringWriter();
      stringWriter.write("<group>\n");

      Iterator classes = lazyClassDefinitionList().iterator();

      while (classes.hasNext()) {
        ComponentEntity entity = (ComponentEntity) classes.next();
        entity.exportMoML(stringWriter, 1);
      }

      Iterator entities = lazyEntityList().iterator();

      while (entities.hasNext()) {
        ComponentEntity entity = (ComponentEntity) entities.next();
        entity.exportMoML(stringWriter, 1);
      }

      // FIXME: Include relations and links!

      stringWriter.write("</group>");
      return stringWriter.toString();
    } catch (IOException ex) {
      return "";
    }
  }
  private void write(
      MonitorLevel level,
      long timestamp,
      String message,
      Object[] args,
      OutputStream stream,
      DateFormat format) {
    message = MessageFormatter.format(message, args);

    Throwable e = null;
    for (Object o : args) {
      if (o instanceof Throwable) {
        e = (Throwable) o;
      }
    }
    if (e != null) {
      StringWriter writer = new StringWriter();
      PrintWriter pw = new PrintWriter(writer);
      if (message != null) {
        writer.write(message);
      }
      writer.write("\n");
      e.printStackTrace(pw);
      message = writer.toString();
    }

    byte[] bytes =
        ("[" + level + " " + format.format(new Date(timestamp)) + "] " + message + "\n").getBytes();

    try {
      stream.write(bytes);
    } catch (IOException ex) {
      ex.printStackTrace();
    }
  }
예제 #7
0
  /**
   * Returns true if the description is consistent (i.e. if it is * possible for there to exist
   * models in which the extension of the class is non-empty.
   */
  public boolean isConsistent(OWLDescription d1) throws OWLException {
    checkStatus();
    StringWriter sw = new StringWriter();
    sw.write(
        "<asks xmlns=\"http://dl.kr.org/dig/lang\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://dl.kr.org/dig/lang dig.xsd\">");

    sw.write("<satisfiable id=\"q\">");
    /* Add the rendered description here */
    renderer.reset();
    d1.accept(renderer);
    sw.write(renderer.result());
    sw.write("</satisfiable>");
    sw.write("</asks>");

    StringWriter response = new StringWriter();
    try {
      digReasoner.request(new StringReader(sw.toString()), response);
    } catch (Exception e) {
      throw new OWLException(e.getMessage());
    }

    uk.ac.man.cs.img.dig.helper.Response serverResponse =
        new uk.ac.man.cs.img.dig.helper.Response(response.toString());

    org.w3c.dom.Element r = serverResponse.extractResponse("q");
    return (r.getTagName().equals("true"));
  }
예제 #8
0
  private void serializeType(
      StringWriter writer,
      String nestedFieldName,
      MetaField field,
      UserData data,
      boolean printField) {
    if (printField) {
      writer.write("<" + field.getName() + ">");
    }

    if (field instanceof MetaPrimitive) { // Primitive
      this.serializePrimitive(writer, nestedFieldName, data, field);
    } else if (field instanceof MetaEnum) { // Enumeration
      this.serializeEnum(writer, nestedFieldName, data);
    } else if (field instanceof MetaUnion) { // Union
      this.serializeUnion(writer, nestedFieldName, (MetaUnion) field, data);
    } else if (field instanceof MetaStruct) { // Structure
      this.serializeStruct(writer, nestedFieldName, (MetaStruct) field, data);
    } else if (field instanceof MetaClass) { // Class
      this.serializeClass(writer, nestedFieldName, (MetaClass) field, data);
    } else if (field instanceof MetaCollection) { // Collection
      this.serializeCollection(writer, nestedFieldName, (MetaCollection) field, data);
    }
    if (printField) {
      writer.write("</" + field.getName() + ">");
    }
  }
 public String toString() {
   StringWriter writer = new StringWriter();
   writer.write("Person: ");
   writer.write(getName());
   writer.write(" ");
   return writer.toString();
 }
  /**
   * Trains a boundary POS prioritization model (AKA a figure-of-merit, or FOM). Parses the training
   * corpus, constrained by the gold trees, and learns prioritization probabilities from the
   * resulting parses.
   *
   * @param sparseMatrixGrammar
   * @return a boundary POS figure of merit model.
   */
  protected BoundaryPosModel trainPosFom(final LeftCscSparseMatrixGrammar sparseMatrixGrammar) {

    try {
      // Constrained parse the training corpus
      final ParserDriver opts = new ParserDriver();
      opts.cellSelectorModel = ConstrainedCellSelector.MODEL;
      opts.researchParserType = ResearchParserType.ConstrainedCartesianProductHashMl;
      final ConstrainedCphSpmlParser constrainedParser =
          new ConstrainedCphSpmlParser(opts, sparseMatrixGrammar);

      final StringWriter binaryConstrainedParses = new StringWriter(30 * 1024 * 1024);
      for (final String inputTree : trainingCorpus) {
        final ParseTask parseTask = constrainedParser.parseSentence(inputTree);
        binaryConstrainedParses.write(parseTask.binaryParse.toString());
        binaryConstrainedParses.write('\n');
      }

      final StringWriter serializedFomModel = new StringWriter(30 * 1024 * 1024);
      BoundaryPosModel.train(
          sparseMatrixGrammar,
          new BufferedReader(new StringReader(binaryConstrainedParses.toString())),
          new BufferedWriter(serializedFomModel),
          .5f,
          false,
          2);

      final BufferedReader fomModelReader =
          new BufferedReader(new StringReader(serializedFomModel.toString()));
      return new BoundaryPosModel(FOMType.BoundaryPOS, sparseMatrixGrammar, fomModelReader);

    } catch (final IOException e) {
      // StringWriter and StringReader should never IOException
      throw new AssertionError(e);
    }
  }
  protected String getGroupSearchFilter(LdapGroupQuery query) {

    StringWriter search = new StringWriter();
    search.write("(&");

    // restrict to groups
    search.write(ldapConfiguration.getGroupSearchFilter());

    // add additional filters from query
    if (query.getId() != null) {
      addFilter(ldapConfiguration.getGroupIdAttribute(), query.getId(), search);
    }
    if (query.getName() != null) {
      addFilter(ldapConfiguration.getGroupNameAttribute(), query.getName(), search);
    }
    if (query.getNameLike() != null) {
      addFilter(ldapConfiguration.getGroupNameAttribute(), query.getNameLike(), search);
    }
    if (query.getUserId() != null) {
      String userDn = null;
      if (ldapConfiguration.isUsePosixGroups()) {
        userDn = query.getUserId();
      } else {
        userDn = getDnForUser(query.getUserId());
      }
      addFilter(
          ldapConfiguration.getGroupMemberAttribute(), escapeLDAPSearchFilter(userDn), search);
    }
    search.write(")");

    return search.toString();
  }
예제 #12
0
파일: DAVE.java 프로젝트: nasa/DAVEtools
  /**
   * Static method that turns punctuated sentence into filename.
   *
   * <p>Creates acceptable filename by
   *
   * <ul>
   *   <li>converting whitespace to single underscores
   *   <li>removing commas and periods
   *   <li>limiting result to 32 chars (arbitrary)
   * </ul>
   *
   * @param inString contains sentence or phrase to convert
   */
  static String toFileName(String inString) {
    int limit = 32; // max file name length

    StringBuilder buf = new StringBuilder(inString);
    StringWriter fileName = new StringWriter(limit);

    for (int i = 0; (i < buf.length()) && (fileName.getBuffer().length() < limit); i++) {
      char c = buf.charAt(i);
      switch (c) {
        case '.':
        case ',':
        case ';':
        case ':':
        case '\'':
        case '"':
        case '(':
        case ')':
        case '[':
        case ']':
        case '{':
        case '}':
          break;
        case ' ': // ignore whitespace (space & tab)
        case '\t':
          fileName.write('_');
          break;
        default:
          fileName.write(c);
      }
    }
    return fileName.toString();
  }
예제 #13
0
    public Reporter(File file) {
      try {
        if (!file.exists()) {
          file.createNewFile();
        }
        writer = new FileWriter(file);
        writer.write(
            "*****************************************************************************************\n");
        writer.write(
            "**** JSR 363 - Units of Measurement, Technical Compatibility Kit, version 1.0\n");
        writer.write(
            "*****************************************************************************************\n\n");
        writer.write("Executed on " + new java.util.Date() + "\n\n");

        // System.out:
        stringWriter.write(
            "*****************************************************************************************\n");
        stringWriter.write(
            "**** JSR 363 - Units of Measurement, Technical Compatibility Kit, version 1.0\n");
        stringWriter.write(
            "*****************************************************************************************\n\n");
        stringWriter.write("Executed on " + new java.util.Date() + "\n\n");
      } catch (IOException e) {
        e.printStackTrace();
        System.exit(-1);
      }
    }
예제 #14
0
 private static String getGetterSetterMethodName(String propertyName, String operation) {
   StringWriter writer = new StringWriter();
   writer.write(operation);
   writer.write(Character.toUpperCase(propertyName.charAt(0)));
   writer.write(propertyName.substring(1));
   return writer.toString();
 }
  @Override
  protected void correctnessCheck(
      final InstanceTaxonomyTestOutput<?> actualOutput,
      final InstanceTaxonomyTestOutput<?> expectedOutput)
      throws ElkException {

    final InstanceTaxonomy<?, ?> expected = expectedOutput.getTaxonomy();

    final InstanceTaxonomy<?, ?> incremental = actualOutput.getTaxonomy();

    if (TaxonomyHasher.hash(expected) != TaxonomyHasher.hash(incremental)
        || !expected.equals(incremental)) {
      StringWriter writer = new StringWriter();

      try {
        writer.write("EXPECTED TAXONOMY:\n");
        TaxonomyPrinter.dumpInstanceTaxomomy(expected, writer, false);
        writer.write("\nINCREMENTAL TAXONOMY:\n");
        TaxonomyPrinter.dumpInstanceTaxomomy(incremental, writer, false);
        writer.flush();
      } catch (IOException ioe) {
        // TODO
      }

      fail(writer.getBuffer().toString());
    }
  }
 @Deprecated
 public String getValues(String sep) {
   java.io.StringWriter out = new java.io.StringWriter();
   {
     Object valueO = getId();
     String valueS;
     if (valueO != null) valueS = valueO.toString();
     else valueS = "";
     valueS = valueS.replaceAll("\r\n", " ").replaceAll("\n", " ").replaceAll("\r", " ");
     valueS = valueS.replaceAll("\t", " ").replaceAll(sep, " ");
     out.write(valueS + sep);
   }
   {
     Object valueO = get__Type();
     String valueS;
     if (valueO != null) valueS = valueO.toString();
     else valueS = "";
     valueS = valueS.replaceAll("\r\n", " ").replaceAll("\n", " ").replaceAll("\r", " ");
     valueS = valueS.replaceAll("\t", " ").replaceAll(sep, " ");
     out.write(valueS + sep);
   }
   {
     Object valueO = getName();
     String valueS;
     if (valueO != null) valueS = valueO.toString();
     else valueS = "";
     valueS = valueS.replaceAll("\r\n", " ").replaceAll("\n", " ").replaceAll("\r", " ");
     valueS = valueS.replaceAll("\t", " ").replaceAll(sep, " ");
     out.write(valueS);
   }
   return out.toString();
 }
 public void toPrecedenceFreeEPL(StringWriter writer) {
   writer.write("cast(");
   this.getChildren().get(0).toEPL(writer, ExpressionPrecedenceEnum.MINIMUM);
   writer.write(", ");
   writer.write(typeName);
   writer.write(")");
 }
예제 #18
0
  @Override
  public synchronized String serializeUserData(UserData data) throws TransformationException {
    if (data == null) {
      throw new TransformationException("Supplied UserData is not valid.");
    }
    StringWriter writer = new StringWriter();
    type = data.getUserDataType();
    MetaField[] fields = type.getFields();
    MetaField field;

    writer.write("<object>");

    for (int i = 0; i < fields.length; i++) {
      field = fields[i];
      this.serializeType(writer, field.getName(), field, data, true);
    }

    writer.write("</object>");
    writer.flush();
    /*
     * logger.logp(java.util.logging.Level.FINEST, "UserDataSerializerXML",
     * "serializeUserData", "Serialized data:\n" + writer.toString());
     */
    return writer.toString();
  }
예제 #19
0
 public String toString() {
   StringWriter writer = new StringWriter();
   writer.write(Helper.getShortClassName(getClass()));
   writer.write("(");
   writer.write(getValue().toString());
   writer.write(")");
   return writer.toString();
 }
예제 #20
0
  /** Print the first & last name */
  public String toString() {
    StringWriter writer = new StringWriter();

    writer.write("Employee: ");
    writer.write(getFirstName());
    writer.write(" ");
    writer.write(getLastName());
    return writer.toString();
  }
 public static String toQueryPlan(List<QueryGraphValueEntryRange> rangeKeyPairs) {
   StringWriter writer = new StringWriter();
   String delimiter = "";
   for (QueryGraphValueEntryRange item : rangeKeyPairs) {
     writer.write(delimiter);
     writer.write(item.toQueryPlan());
     delimiter = ", ";
   }
   return writer.toString();
 }
 protected static String toStringPath(String[] attributePath, int position) {
   StringWriter writer = new StringWriter();
   for (int index = 0; index <= position; index++) {
     writer.write(attributePath[index]);
     if (index < position) {
       writer.write(".");
     }
   }
   return writer.toString();
 }
  /** Print the SmallProject's information. */
  public String toString() {
    java.io.StringWriter writer = new java.io.StringWriter();

    writer.write("STI_SmallProject: ");
    writer.write(getName());
    writer.write(" ");
    writer.write(getDescription());
    writer.write("");
    return writer.toString();
  }
  public String toString() {
    StringWriter writer = new StringWriter();

    writer.write("Large Project: ");
    writer.write(getName());
    writer.write(" ");
    writer.write(" " + getBudget());
    writer.write(" ");
    return writer.toString();
  }
예제 #25
0
 /**
  * Renders the element in textual representation.
  *
  * @param writer to output to
  */
 public void toEPLElement(StringWriter writer) {
   expression.toEPL(writer, ExpressionPrecedenceEnum.MINIMUM);
   if (annotatedByEventFlag) {
     writer.write(" @eventbean");
   }
   if (asName != null) {
     writer.write(" as ");
     writer.write(asName);
   }
 }
예제 #26
0
  @Override
  public String toJpdl() throws InvalidModelException {
    StringWriter jpdl = new StringWriter();
    jpdl.write("  <esb");

    jpdl.write(JsonToJpdl.transformAttribute("name", name));

    try {
      jpdl.write(JsonToJpdl.transformRequieredAttribute("category", category));
      jpdl.write(JsonToJpdl.transformRequieredAttribute("service", service));
    } catch (InvalidModelException e) {
      throw new InvalidModelException("Invalid Esb activity. " + e.getMessage());
    }

    if (bounds != null) {
      jpdl.write(bounds.toJpdl());
    } else {
      throw new InvalidModelException("Invalid ESB activity. Bounds is missing.");
    }

    jpdl.write(" >\n");

    for (Part p : part) {
      jpdl.write(p.toJpdl());
    }

    for (Transition t : outgoings) {
      jpdl.write(t.toJpdl());
    }

    jpdl.write("  </esb>\n\n");

    return jpdl.toString();
  }
 /** Prints using deprecate APIs. */
 @SuppressWarnings("deprecation")
 public void test() throws Exception {
   StringWriter writer = new StringWriter();
   writer.write(String.valueOf(this.date.getYear()));
   writer.write(String.valueOf(this.date.getDate()));
   writer.write(String.valueOf(this.date.getMonth()));
   writer.write(String.valueOf(this.date.getHours()));
   writer.write(String.valueOf(this.date.getMinutes()));
   writer.write(String.valueOf(this.date.getSeconds()));
   writer.toString();
 }
예제 #28
0
 public String toJpdl() throws InvalidModelException {
   StringWriter jpdl = new StringWriter();
   jpdl.write("<arg>\n");
   if (child != null) {
     jpdl.write(child.toJpdl());
   } else {
     throw new InvalidModelException("Invalid Arg. Object or String is missing");
   }
   jpdl.write("</arg>\n");
   return jpdl.toString();
 }
예제 #29
0
 private String transformIntoWindowsNewLines(String s) {
   StringWriter writer = new StringWriter();
   for (char c : s.toCharArray()) {
     if (c == '\n') {
       writer.write('\r');
       writer.write('\n');
     } else if (c != '\r') {
       writer.write(c);
     }
   }
   return writer.toString();
 }
예제 #30
0
  public static File toFile(String... filePathParts) {
    final StringWriter filePathBuffer = new StringWriter();

    for (int i = 0; i < filePathParts.length; i++) {
      filePathBuffer.write(filePathParts[i]);
      if (i + 1 < filePathParts.length) {
        filePathBuffer.write(FILE_SEPARATOR);
      }
    }

    return new File(filePathBuffer.toString());
  }