@Override
  protected void fillVoiceXmlDocument(
      Document document, Element formElement, VoiceXmlDialogueContext dialogueContext)
      throws VoiceXmlDocumentRenderingException {
    addVariableDeclarations(formElement, mVariables);

    Element blockElement = DomUtils.appendNewElement(formElement, BLOCK_ELEMENT);

    if (mScript != null) {
      Element scriptElement = DomUtils.appendNewElement(blockElement, SCRIPT_ELEMENT);
      DomUtils.appendNewText(scriptElement, mScript);
    }

    StringBuffer scriptBuffer = new StringBuffer();

    scriptBuffer.append(RIVR_SCOPE_OBJECT + ".addValueResult({");
    boolean first = true;
    for (VariableDeclaration variableDeclaration : mVariables) {
      if (!first) {
        scriptBuffer.append(", ");
      } else {
        first = false;
      }
      scriptBuffer.append("\"");
      scriptBuffer.append(variableDeclaration.getName());
      scriptBuffer.append("\": ");
      scriptBuffer.append("dialog.");
      scriptBuffer.append(variableDeclaration.getName());
    }
    scriptBuffer.append("});");

    createScript(blockElement, scriptBuffer.toString());
    createGotoSubmit(blockElement);
  }
Exemple #2
0
  /**
   * Returns a String representation of the <code>&lt;saml:Attribute&gt;</code> element.
   *
   * @param includeNS Determines whether or not the namespace qualifier is prepended to the Element
   *     when converted
   * @param declareNS Determines whether or not the namespace is declared within the Element.
   * @return A string containing the valid XML for this element
   */
  public String toString(boolean includeNS, boolean declareNS) {
    StringBuffer result = new StringBuffer(1000);
    String prefix = "";
    String uri = "";
    if (includeNS) {
      prefix = SAMLConstants.ASSERTION_PREFIX;
    }
    if (declareNS) {
      uri = SAMLConstants.assertionDeclareStr;
    }
    result
        .append("<")
        .append(prefix)
        .append("Attribute")
        .append(uri)
        .append(" AttributeName=\"")
        .append(_attributeName)
        .append("\" AttributeNamespace=\"")
        .append(_attributeNameSpace)
        .append("\">\n");

    Iterator iter = _attributeValue.iterator();
    while (iter.hasNext()) {
      result.append(XMLUtils.printAttributeValue((Element) iter.next(), prefix)).append("\n");
    }
    result.append("</").append(prefix).append("Attribute>\n");
    return result.toString();
  }
 /*   public void cargar() throws Exception
 {
     try
     {
         if(_infos.getOutputWriter() != null)
         {
              _destinoXML = domToXml(_infos.getOutputWriter());
         } else
         {
             _destinoXML = domToXml(new FileOutputStream(_infos.getURLasString()));
         }
     }
     catch(Exception ex)
     {
         throw ex;
     }
 } */
 public static org.w3c.dom.Document xmlToDom(
     Reader procedencia, OutputStream salida, boolean valid_mode) throws Exception {
   try {
     DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
     DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
     StringBuffer cadena = new StringBuffer("");
     char[] b = new char[255];
     int bytesRead = 0;
     while ((bytesRead = procedencia.read(b)) != -1) {
       cadena.append(b, 0, bytesRead);
     }
     System.out.println(cadena.toString());
     ByteArrayInputStream entradaParser = new ByteArrayInputStream(cadena.toString().getBytes());
     org.w3c.dom.Document doc = docBuilder.parse((InputStream) entradaParser);
     return doc;
     /*DOMParser parser = new DOMParser();
     parser.setErrorStream(salida);
     parser.showWarnings(valid_mode);
     if(valid_mode)
         parser.setValidationMode(2);
     else
         parser.setValidationMode(0);
     parser.parse(procedencia);
     XMLDocument xml = parser.getDocument();
     return xml;*/
   } catch (Exception e) {
     throw e;
   }
 }
Exemple #4
0
 public static String text(NodeList nodeList) {
   StringBuffer sb = new StringBuffer();
   for (int i = 0; i < nodeList.getLength(); i++) {
     sb.append(text(nodeList.item(i)));
   }
   return sb.toString();
 }
  /**
   * Method getStrFromNode
   *
   * @param xpathnode
   * @return the string for the node.
   */
  public static String getStrFromNode(Node xpathnode) {

    if (xpathnode.getNodeType() == Node.TEXT_NODE) {

      // we iterate over all siblings of the context node because eventually,
      // the text is "polluted" with pi's or comments
      StringBuffer sb = new StringBuffer();

      for (Node currentSibling = xpathnode.getParentNode().getFirstChild();
          currentSibling != null;
          currentSibling = currentSibling.getNextSibling()) {
        if (currentSibling.getNodeType() == Node.TEXT_NODE) {
          sb.append(((Text) currentSibling).getData());
        }
      }

      return sb.toString();
    } else if (xpathnode.getNodeType() == Node.ATTRIBUTE_NODE) {
      return ((Attr) xpathnode).getNodeValue();
    } else if (xpathnode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
      return ((ProcessingInstruction) xpathnode).getNodeValue();
    }

    return null;
  }
Exemple #6
0
 /**
  * Adds <code>AttributeValue</code> to the Attribute.
  *
  * @param value A String representing <code>AttributeValue</code>.
  * @exception SAMLException
  */
 public void addAttributeValue(String value) throws SAMLException {
   if (value == null || value.length() == 0) {
     if (SAMLUtilsCommon.debug.messageEnabled()) {
       SAMLUtilsCommon.debug.message("addAttributeValue: Input is null");
     }
     throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString("nullInput"));
   }
   StringBuffer sb = new StringBuffer(300);
   sb.append("<")
       .append(SAMLConstants.ASSERTION_PREFIX)
       .append("AttributeValue")
       .append(SAMLConstants.assertionDeclareStr)
       .append(">")
       .append(value)
       .append("</")
       .append(SAMLConstants.ASSERTION_PREFIX)
       .append("AttributeValue>");
   try {
     Element ele =
         XMLUtils.toDOMDocument(sb.toString().trim(), SAMLUtilsCommon.debug).getDocumentElement();
     if (_attributeValue == null) {
       _attributeValue = new ArrayList();
     }
     if (!(_attributeValue.add(ele))) {
       if (SAMLUtilsCommon.debug.messageEnabled()) {
         SAMLUtilsCommon.debug.message(
             "Attribute: failed to " + "add to the attribute value list.");
       }
       throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString("addListError"));
     }
   } catch (Exception e) {
     SAMLUtilsCommon.debug.error("addAttributeValue error", e);
     throw new SAMLRequesterException("Exception in addAttributeValue" + e.getMessage());
   }
 }
  public static String escape(String query) {
    if (query == null) {
      return null;
    }
    int cnt = ops.length;

    for (int i = 0; i < cnt; i++) {
      query = query.replace(ops[i], ops1[i]);
    }
    cnt = zhuan1.length;
    for (int i = 0; i < cnt; i++) {
      query = query.replace(zhuan1[i], zhuan2[i]);
    }
    String strConv = "+-&|!(){}[]^\"~*?:\\";
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < query.length(); i++) {
      char ch = query.charAt(i);
      if (strConv.indexOf(ch) != -1) {
        sb.append("\\");
        sb.append(ch);
      } else {
        sb.append(ch);
      }
    }

    return sb.toString();
  }
Exemple #8
0
 private ClassLoaderStrategy getClassLoaderStrategy(String fullyQualifiedClassName)
     throws Exception {
   try {
     // Get just the package name
     StringBuffer sb = new StringBuffer(fullyQualifiedClassName);
     sb.delete(sb.lastIndexOf("."), sb.length());
     currentPackage = sb.toString();
     // Retrieve the Java classpath from the system properties
     String cp = System.getProperty("java.class.path");
     String sepChar = System.getProperty("path.separator");
     String[] paths = StringUtils.pieceList(cp, sepChar.charAt(0));
     ClassLoaderStrategy cl =
         ClassLoaderUtil.getClassLoader(ClassLoaderUtil.FILE_SYSTEM_CLASS_LOADER, new String[] {});
     // Iterate through paths until class with the specified name is found
     String classpath = StringUtils.replaceChar(currentPackage, '.', File.separatorChar);
     for (int i = 0; i < paths.length; i++) {
       Class[] classes = cl.getClasses(paths[i] + File.separatorChar + classpath, currentPackage);
       for (int j = 0; j < classes.length; j++) {
         if (classes[j].getName().equals(fullyQualifiedClassName)) {
           return ClassLoaderUtil.getClassLoader(
               ClassLoaderUtil.FILE_SYSTEM_CLASS_LOADER, new String[] {paths[i]});
         }
       }
     }
     throw new Exception("Class could not be found.");
   } catch (Exception e) {
     System.err.println("Exception creating class loader strategy.");
     System.err.println(e.getMessage());
     throw e;
   }
 }
 /** Produces an indented XML representation of this object. */
 public StringBuffer toXML() {
   StringBuffer sb = new StringBuffer(500);
   sb.append("<ogc:").append(getOperatorName()).append(">");
   sb.append(expr1.toXML());
   sb.append(expr2.toXML());
   sb.append("</ogc:").append(getOperatorName()).append(">");
   return sb;
 }
Exemple #10
0
 public static Node indent(Document doc, int level) {
   StringBuffer sb = new StringBuffer();
   final String basicIndent = "    ";
   int x;
   for (x = 0; x < level; x++) {
     sb.append(basicIndent);
   }
   return doc.createTextNode(sb.toString());
 }
Exemple #11
0
 public String getPropertyName(String name) {
   // Set the first letter of the property name to lower-case
   StringBuffer propertyName = new StringBuffer(name);
   char c = propertyName.charAt(0);
   if (c >= 'A' && c <= 'Z') {
     c -= 'A' - 'a';
     propertyName.setCharAt(0, c);
   }
   return propertyName.toString();
 }
 // TODO: Of course, there is no Element.getTextContent() either...
 public static String getTextContent(Node node) {
   StringBuffer buffer = new StringBuffer();
   NodeList childList = node.getChildNodes();
   for (int i = 0; i < childList.getLength(); i++) {
     Node child = childList.item(i);
     if (child.getNodeType() != Node.TEXT_NODE) continue; // skip non-text nodes
     buffer.append(child.getNodeValue());
   }
   return buffer.toString();
 }
Exemple #13
0
  /**
   * Can be used to encode values that contain invalid XML characters. At SAX parser end must be
   * used pair method to get original value.
   *
   * @param val data to be converted
   * @param start offset
   * @param len count
   * @since 1.29
   */
  public static String toHex(byte[] val, int start, int len) {

    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < len; i++) {
      byte b = val[start + i];
      buf.append(DEC2HEX[(b & 0xf0) >> 4]);
      buf.append(DEC2HEX[b & 0x0f]);
    }
    return buf.toString();
  }
Exemple #14
0
 /**
  * Makes an XML text representation.
  *
  * @param buffer
  */
 public void makeTextElement(StringBuffer buffer) {
   int size;
   buffer.append("<legal");
   if (id_ != null) {
     buffer.append(" id=\"");
     buffer.append(URelaxer.escapeAttrQuot(URelaxer.getString(getId())));
     buffer.append("\"");
   }
   if (xmlLang_ != null) {
     buffer.append(" xml:lang=\"");
     buffer.append(URelaxer.escapeAttrQuot(URelaxer.getString(getXmlLang())));
     buffer.append("\"");
   }
   size = this.content_.size();
   for (int i = 0; i < size; i++) {
     IFtContentMixMixed value = (IFtContentMixMixed) this.content_.get(i);
     value.makeTextAttribute(buffer);
   }
   buffer.append(">");
   size = this.content_.size();
   for (int i = 0; i < size; i++) {
     IFtContentMixMixed value = (IFtContentMixMixed) this.content_.get(i);
     value.makeTextElement(buffer);
   }
   buffer.append("</legal>");
 }
Exemple #15
0
 /** @deprecated use allText(Element elem, boolean trim) */
 public static String allTextFromElement(Element elem, boolean trim) throws DOMException {
   StringBuffer textBuf = new StringBuffer();
   NodeList nl = elem.getChildNodes();
   for (int j = 0, len = nl.getLength(); j < len; ++j) {
     Node node = nl.item(j);
     if (node instanceof Text) // includes Text and CDATA!
     textBuf.append(node.getNodeValue());
   }
   String out = textBuf.toString();
   return (trim ? out.trim() : out);
 }
 private String getFeatureIDs() {
   StringBuffer buffer = new StringBuffer();
   Object[] objects = fPage.getSelectedItems();
   for (int i = 0; i < objects.length; i++) {
     Object object = objects[i];
     if (object instanceof IFeatureModel) {
       buffer.append(((IFeatureModel) object).getFeature().getId());
       if (i < objects.length - 1) buffer.append(","); // $NON-NLS-1$
     }
   }
   return buffer.toString();
 }
  public String toString() {
    StringBuffer strBuf = new StringBuffer();

    strBuf.append("UnknownExtensibilityElement (" + elementType + "):");
    strBuf.append("\nrequired=" + required);

    if (element != null) {
      strBuf.append("\nelement=" + element);
    }

    return strBuf.toString();
  }
 public String toString() {
   if (isEmpty()) {
     return "";
   }
   StringBuffer sb = new StringBuffer();
   Iterator<NodeLayout> e = nodes.iterator();
   while (e.hasNext()) sb.append((e.next()).toString());
   sb.append("\n");
   Iterator<EdgeLayout> ee = edges.iterator();
   while (ee.hasNext()) sb.append((ee.next()).toString());
   return sb.toString();
 }
  /**
   * _more_
   *
   * @param properties _more_
   * @return _more_
   */
  public String makePropertiesString(Hashtable properties) {
    StringBuffer sb = new StringBuffer();
    for (java.util.Enumeration keys = properties.keys(); keys.hasMoreElements(); ) {
      Object key = keys.nextElement();
      sb.append(key);
      sb.append("=");
      sb.append(properties.get(key));
      sb.append("\n");
    }

    return sb.toString();
  }
 public String toString() {
   StringBuffer sb = new StringBuffer();
   sb.append(sourcepid + "," + sourceNode + "," + targetpid + "," + targetNode + ",");
   Iterator<LayoutPoint> e = bends.iterator();
   LayoutPoint b;
   while (e.hasNext()) {
     b = (LayoutPoint) e.next();
     sb.append(b.x + "," + b.y + ",");
   }
   sb.append("\n");
   return sb.toString();
 }
 private static String readFileAsString(String filePath) throws IOException {
   StringBuffer fileData = new StringBuffer();
   BufferedReader reader = new BufferedReader(new FileReader(filePath));
   char[] buf = new char[1024];
   int numRead = 0;
   while ((numRead = reader.read(buf)) != -1) {
     String readData = String.valueOf(buf, 0, numRead);
     fileData.append(readData);
   }
   reader.close();
   return fileData.toString();
 }
  /**
   * Initializes this object.
   *
   * @param key Property-key to use for locating initialization properties.
   * @param type Property-type to use for locating initialization properties.
   * @exception ProcessingException when initialization fails
   */
  public void initialize(String key, String type) throws ProcessingException {
    super.initialize(key, type);

    StringBuffer errorBuf = new StringBuffer();

    // serverName = getRequiredProperty(SERVER_NAME_PROP, errorBuf);

    headerLocation = getPropertyValue(NF_HEADER_LOCATION_PROP);

    isAsyncLocation = getPropertyValue(IS_ASYNCHRONOUS_LOCATION_PROP);

    orbAgentAddr = getPropertyValue(ORB_AGENT_ADDR_PROP);

    orbAgentPort = getPropertyValue(ORB_AGENT_PORT_PROP);

    orbAgentAddrLocation = getPropertyValue(ORB_AGENT_ADDR_PROP_LOCATION);

    orbAgentPortLocation = getPropertyValue(ORB_AGENT_PORT_PROP_LOCATION);

    if (!StringUtils.hasValue(isAsyncLocation)) {
      try {
        isAsync =
            StringUtils.getBoolean(
                (String) getRequiredPropertyValue(DEFAULT_IS_ASYNCHRONOUS_PROP, errorBuf));
      } catch (FrameworkException fe) {
        errorBuf.append(
            "No value is specified for either "
                + IS_ASYNCHRONOUS_LOCATION_PROP
                + "or"
                + DEFAULT_IS_ASYNCHRONOUS_PROP
                + ". One of the values should be present"
                + fe.getMessage());
      }
    }

    if (!StringUtils.hasValue(headerLocation)) {
      try {
        header = getRequiredPropertyValue(DEFAULT_HEADER_PROP, errorBuf);
      } catch (Exception e) {
        errorBuf.append(
            "No value is specified for "
                + NF_HEADER_LOCATION_PROP
                + "or"
                + DEFAULT_HEADER_PROP
                + ". One of the values should be present"
                + e.getMessage());
      }
    }

    if (errorBuf.length() > 0) throw new ProcessingException(errorBuf.toString());
  }
 // Dump the content of this bean returning it as a String
 public void dump(StringBuffer str, String indent) {
   String s;
   Object o;
   org.netbeans.modules.schema2beans.BaseBean n;
   str.append(indent);
   str.append("FileEntry[" + this.sizeFileEntry() + "]"); // NOI18N
   for (int i = 0; i < this.sizeFileEntry(); i++) {
     str.append(indent + "\t");
     str.append("#" + i + ":");
     n = (org.netbeans.modules.schema2beans.BaseBean) this.getFileEntry(i);
     if (n != null) n.dump(str, indent + "\t"); // NOI18N
     else str.append(indent + "\tnull"); // NOI18N
     this.dumpAttributes(FILE_ENTRY, i, str, indent);
   }
 }
Exemple #24
0
 /**
  * ** Filters an ID String, convertering all letters to lowercase and ** removing invalid
  * characters ** @param text The ID String to filter ** @return The filtered ID String
  */
 public static String FilterID(String text) {
   // ie. "sky.12", "acme@123"
   if (text != null) {
     StringBuffer sb = new StringBuffer();
     for (int i = 0; i < text.length(); i++) {
       char ch = Character.toLowerCase(text.charAt(i));
       if (DBRecordKey.isValidIDChar(ch)) {
         sb.append(ch);
       }
     }
     return sb.toString();
   } else {
     return "";
   }
 }
 /**
  * _more_
  *
  * @param request _more_
  * @param entry _more_
  * @param tabTitles _more_
  * @param tabContents _more_
  */
 public void addToInformationTabs(
     Request request, Entry entry, List<String> tabTitles, List<String> tabContents) {
   //        super.addToInformationTabs(request, entry, tabTitles, tabContents);
   try {
     RecordOutputHandler outputHandler = getRecordOutputHandler();
     if (outputHandler != null) {
       tabTitles.add(msg("File Format"));
       StringBuffer sb = new StringBuffer();
       RecordEntry recordEntry = outputHandler.doMakeEntry(request, entry);
       outputHandler.getFormHandler().getEntryMetadata(request, recordEntry, sb);
       tabContents.add(sb.toString());
     }
   } catch (Exception exc) {
     throw new RuntimeException(exc);
   }
 }
 private void assertNodeName(Node pNode, String... pExpected) {
   for (String expected : pExpected) {
     if (pNode.getNodeName().equals(expected)) {
       return;
     }
   }
   StringBuffer buffer = new StringBuffer();
   for (int i = 0; i < pExpected.length; i++) {
     buffer.append(pExpected[i]);
     if (i < pExpected.length - 1) {
       buffer.append(",");
     }
   }
   throw new SecurityException(
       "Expected element " + buffer.toString() + " but got " + pNode.getNodeName());
 }
Exemple #27
0
 /**
  * ** Returns a string representation of this object ** @return The string representation of this
  * object
  */
 public String toString() {
   DBField kf[] = this.getKeyFields();
   if (kf.length == 0) {
     return "<null>";
   } else {
     DBFieldValues fv = this.getFieldValues();
     StringBuffer sb = new StringBuffer();
     for (int i = 0; i < kf.length; i++) {
       if (i > 0) {
         sb.append(",");
       }
       sb.append(fv.getFieldValueAsString(kf[i].getName()));
     }
     return sb.toString();
   }
 }
Exemple #28
0
  /** Normalizes the given string. */
  protected String normalize(String s) {
    StringBuffer str = new StringBuffer();

    int len = (s != null) ? s.length() : 0;
    for (int i = 0; i < len; i++) {
      char ch = s.charAt(i);
      switch (ch) {
        case '<':
          {
            str.append("&lt;");
            break;
          }
        case '>':
          {
            str.append("&gt;");
            break;
          }
        case '&':
          {
            str.append("&amp;");
            break;
          }
        case '"':
          {
            str.append("&quot;");
            break;
          }
        case '\r':
        case '\n':
          {
            if (canonical) {
              str.append("&#");
              str.append(Integer.toString(ch));
              str.append(';');
              break;
            }
            // else, default append char
          }
        default:
          {
            str.append(ch);
          }
      }
    }

    return (str.toString());
  } // normalize(String):String
 /* return the value of the XML text node (never null) */
 protected static String GetNodeText(Node root) {
   StringBuffer sb = new StringBuffer();
   if (root != null) {
     NodeList list = root.getChildNodes();
     for (int i = 0; i < list.getLength(); i++) {
       Node n = list.item(i);
       if (n.getNodeType() == Node.CDATA_SECTION_NODE) { // CDATA Section
         sb.append(n.getNodeValue());
       } else if (n.getNodeType() == Node.TEXT_NODE) {
         sb.append(n.getNodeValue());
       } else {
         // Print.logWarn("Unrecognized node type: " + n.getNodeType());
       }
     }
   }
   return sb.toString();
 }
Exemple #30
0
  /**
   * Escape passed string as XML attibute value (<code>&lt;</code>, <code>&amp;</code>, <code>'
   * </code> and <code>"</code> will be escaped. Note: An XML processor returns normalized value
   * that can be different.
   *
   * @param val a string to be escaped
   * @return escaped value
   * @throws CharConversionException if val contains an improper XML character
   * @since 1.40
   */
  public static String toAttributeValue(String val) throws CharConversionException {

    if (val == null) throw new CharConversionException("null"); // NOI18N

    if (checkAttributeCharacters(val)) return val;

    StringBuffer buf = new StringBuffer();

    for (int i = 0; i < val.length(); i++) {
      char ch = val.charAt(i);
      if ('<' == ch) {
        buf.append("&lt;");
        continue;
      } else if ('&' == ch) {
        buf.append("&amp;");
        continue;
      } else if ('\'' == ch) {
        buf.append("&apos;");
        continue;
      } else if ('"' == ch) {
        buf.append("&quot;");
        continue;
      }
      buf.append(ch);
    }
    return buf.toString();
  }