/* 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; } }
/** * This utility method is used to get the String representation of this object of <code>InPort * </code> * * @return The String representation of this object. * @since Tifosi2.0 */ public String toString() { String baseString = super.toString(); StringBuffer strBuf = new StringBuffer(); strBuf.append(baseString); strBuf.append(""); strBuf.append("sps inport Details "); strBuf.append("["); strBuf.append("is sync request type = "); strBuf.append(m_bIsSyncRequestType); strBuf.append(", "); strBuf.append("Description = "); strBuf.append(m_strDscription); strBuf.append(", "); strBuf.append("Java Class = "); strBuf.append(m_strJavaClass); strBuf.append(", "); strBuf.append("Port name = "); strBuf.append(m_strPortName); strBuf.append(", "); strBuf.append("XSD = "); strBuf.append(m_strXSD); strBuf.append(", "); if (m_params != null) { strBuf.append("Aliases = "); for (int i = 0; i < m_params.size(); i++) { strBuf.append((i + 1) + ". "); strBuf.append(((Param) m_params.elementAt(i)).toString()); strBuf.append(", "); } } strBuf.append("]"); return strBuf.toString(); }
/** * Returns a String representation of the <code><saml:Attribute></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(); }
/** * Escape passed string as XML attibute value (<code><</code>, <code>&</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("<"); continue; } else if ('&' == ch) { buf.append("&"); continue; } else if ('\'' == ch) { buf.append("'"); continue; } else if ('"' == ch) { buf.append("""); continue; } buf.append(ch); } return buf.toString(); }
@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); }
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(); }
// 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(); }
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; } }
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; } }
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(); }
/** * 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()); } }
/** * 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; }
private String getAddressReverseGeocodeURL(GeoPoint gp) { // - // http://nominatim.openstreetmap.org/reverse?format=xml&addressdetails=1&zoom=18&lat=46.17330&lon=21.29370 StringBuffer sb = new StringBuffer(); RTProperties rtp = this.getProperties(); String url = rtp.getString(PROP_reverseURL, null); if (!StringTools.isBlank(url)) { sb.append(url); } else { String host = rtp.getString(PROP_hostName, HOST_PRIMARY); sb.append("http://"); sb.append(host); if (host.indexOf("mapquest") >= 0) { sb.append("/nominatim/v1/reverse?"); } else { sb.append("/reverse?"); } } sb.append("format=xml&"); sb.append("limit=1&"); // sb.append("osm_type=W&"); sb.append("addressdetails=").append(rtp.getString(PROP_addressdetails, "1")).append("&"); // 0,1 sb.append("zoom=").append(rtp.getString(PROP_zoom, "18")).append("&"); // 0..18 sb.append("email=").append(this.getEmail()).append("&"); // required, per usage policy sb.append("lat=").append(gp.getLatitudeString(GeoPoint.SFORMAT_DEC_5, null)).append("&"); sb.append("lon=").append(gp.getLongitudeString(GeoPoint.SFORMAT_DEC_5, null)); return sb.toString(); }
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()); }
// 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(); }
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(); }
/** * 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(); }
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(); }
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(); }
/** @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 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(); }
/** @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(); }
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(); }
/** * _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 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(); }
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(); }
public Element reportDtElem() { StringBuffer sb = new StringBuffer(255); sb.append(shortTypeName); sb.append(" [ dataSourceName: "); sb.append(pds.getDataSourceName()); sb.append("; identityToken: "); sb.append(pds.getIdentityToken()); sb.append(" ]"); Element dtElem = doc.createElement("dt"); dtElem.appendChild(doc.createTextNode(sb.toString())); return dtElem; }
/** * 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()); }