Esempio n. 1
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();
  }
Esempio n. 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 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();
  }
Esempio n. 4
0
 // Serialize the bean using the specified namespace prefix & uri
 public String serialize(Object bean) throws IntrospectionException, IllegalAccessException {
   // Use the class name as the name of the root element
   String className = bean.getClass().getName();
   String rootElementName = null;
   if (bean.getClass().isAnnotationPresent(ObjectXmlAlias.class)) {
     AnnotatedElement annotatedElement = bean.getClass();
     ObjectXmlAlias aliasAnnotation = annotatedElement.getAnnotation(ObjectXmlAlias.class);
     rootElementName = aliasAnnotation.value();
   }
   // Use the package name as the namespace URI
   Package pkg = bean.getClass().getPackage();
   nsURI = pkg.getName();
   // Remove a trailing semi-colon (;) if present (i.e. if the bean is an array)
   className = StringUtils.deleteTrailingChar(className, ';');
   StringBuffer sb = new StringBuffer(className);
   String objectName = sb.delete(0, sb.lastIndexOf(".") + 1).toString();
   domDocument = createDomDocument(objectName);
   document = domDocument.getDocument();
   Element root = document.getDocumentElement();
   // Parse the bean elements
   getBeanElements(root, rootElementName, className, bean);
   StringBuffer xml = new StringBuffer();
   if (prettyPrint)
     xml.append(domDocument.serialize(lineSeperator, indentChars, includeXmlProlog));
   else xml.append(domDocument.serialize(includeXmlProlog));
   if (!includeTypeInfo) {
     int index = xml.indexOf(root.getNodeName());
     xml.delete(index - 1, index + root.getNodeName().length() + 2);
     xml.delete(xml.length() - root.getNodeName().length() - 4, xml.length());
   }
   return xml.toString();
 }
  public static List<Map<String, Object>> getValues(
      String svrURL, String query, String fileId, int num, String _fq, String skey, String _type) {
    if (svrURL == null || query == null) {
      System.out.println(svrURL);
      return null;
    }
    String q = null, fq = null;

    try {
      // q = URLEncoder.encode("\"" + escape(query) + "\"~10", "UTF-8");
      q = URLEncoder.encode(query, "UTF-8");

      StringBuffer _request = new StringBuffer();
      _request.append(svrURL);
      _request.append("?q=" + q);
      // _request.append("&start=0");

      if (_fq != null && _fq.length() > 0 && !_fq.equals("null")) {
        _request.append("&fq=").append(URLEncoder.encode(_fq, "UTF-8"));
      }
      // _request.append("&rows=" + veriNum).append(
      // "&group=true&group.field=ORIGINAL&group.main=true");
      if (fileId == null && skey == null) _request.append("&rows=" + num).append("&group=false");
      String _final = _request.toString();
      System.out.println(_final);
      if (fileId == null && skey == null) return doSearchResult(_final);
      if (_type == null) return readVerifyValues(_final, skey);
      return null;
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
      return null;
    }
  }
 /** 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;
 }
Esempio n. 7
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();
  }
Esempio n. 8
0
 public String toString() {
   StringBuffer sb = new StringBuffer();
   sb.append(processID + ",");
   sb.append(nodeID + ",");
   if (cofactor.equalsIgnoreCase("true")) {
     sb.append("cofactor");
   }
   sb.append("," + x + "," + y + "\n");
   return sb.toString();
 }
Esempio n. 9
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>");
 }
 /** @param tag */
 private String makeElementNameFromHexadecimalGroupElementValues(AttributeTag tag) {
   StringBuffer str = new StringBuffer();
   str.append("HEX"); // XML element names not allowed to start with a number
   String groupString = Integer.toHexString(tag.getGroup());
   for (int i = groupString.length(); i < 4; ++i) str.append("0");
   str.append(groupString);
   String elementString = Integer.toHexString(tag.getElement());
   for (int i = elementString.length(); i < 4; ++i) str.append("0");
   str.append(elementString);
   return str.toString();
 }
Esempio n. 11
0
 private static String toString(NodeList self) {
   StringBuffer sb = new StringBuffer();
   sb.append("[");
   Iterator it = DefaultGroovyMethods.iterator(self);
   while (it.hasNext()) {
     if (sb.length() > 1) sb.append(", ");
     sb.append(it.next().toString());
   }
   sb.append("]");
   return sb.toString();
 }
Esempio n. 12
0
 public String toBeautifiedString() {
   StringBuffer sb = new StringBuffer();
   sb.append("PID: " + processID);
   sb.append("  Node id: " + nodeID);
   if (cofactor.equalsIgnoreCase("true")) {
     sb.append("\n is Cofactor. ");
   }
   sb.append("\n");
   sb.append("           x: " + x + " y: " + y + "\n\n");
   return sb.toString();
 }
Esempio n. 13
0
  /**
   * _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();
  }
 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();
  }
Esempio n. 16
0
 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();
 }
Esempio n. 17
0
 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();
 }
Esempio n. 18
0
  /**
   * 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());
  }
Esempio n. 19
0
  @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);
  }
Esempio n. 20
0
 // 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);
   }
 }
Esempio n. 21
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());
   }
 }
Esempio n. 22
0
  /**
   * 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;
  }
Esempio n. 23
0
 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());
 }
Esempio n. 24
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();
 }
Esempio n. 25
0
 /*   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;
   }
 }
Esempio n. 26
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();
   }
 }
Esempio n. 27
0
 /* 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();
 }
Esempio n. 28
0
 private String formatName(String name) {
   StringBuffer propertyName = new StringBuffer();
   if (lowerCase) propertyName.append(name.toLowerCase());
   else propertyName.append(name);
   char c = propertyName.charAt(0);
   if (firstLetterUpperCase) {
     if (c >= 'a' && c <= 'z') {
       c += 'A' - 'a';
     }
   } else {
     if (c >= 'A' && c <= 'Z') {
       c -= 'A' - 'a';
     }
   }
   propertyName.setCharAt(0, c);
   return propertyName.toString();
 }
  // Text output
  public void makeNSMappings(StringBuffer buffer) {
    Set keys = prefixByUri_.keySet();
    Iterator iter = keys.iterator();

    while (iter.hasNext()) {
      String uri = (String) iter.next();
      buffer.append(makeNSMapping(uri));
    }
  }
Esempio n. 30
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());
 }