/** * Add a complete tag with content. * * @param tagName name of the tag * @param content content to put in tag, or empty content, if an empty tag should be used * @return this */ public XMLBuffer tag(String tagName, CharSequence content) { if (content.length() == 0) { emptyTag(tagName); } else { startTag(tagName); sb.append(content); endTag(tagName); } return this; }
@Override public SampleResult sample(Entry e) { XMLBuffer xmlBuffer = new XMLBuffer(); xmlBuffer.openTag("ldapanswer"); // $NON-NLS-1$ SampleResult res = new SampleResult(); res.setResponseData("successfull", null); xmlBuffer.openTag("operation"); // $NON-NLS-1$ final String testType = getTest(); xmlBuffer.tag("opertype", testType); // $NON-NLS-1$ log.debug("performing test: " + testType); if (testType.equals(UNBIND)) { res.setSamplerData("Unbind"); xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$ xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$ unbindOp(dirContext, res); } else if (testType.equals(BIND)) { res.setSamplerData("Bind as "+getUserDN()); xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$ xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$ xmlBuffer.tag("connectionTO",getConnTimeOut()); // $NON-NLS-1$ bindOp(res); } else if (testType.equals(SBIND)) { res.setSamplerData("SingleBind as "+getUserDN()); xmlBuffer.tag("baseobj",getRootdn()); // $NON-NLS-1$ xmlBuffer.tag("binddn",getUserDN()); // $NON-NLS-1$ xmlBuffer.tag("connectionTO",getConnTimeOut()); // $NON-NLS-1$ singleBindOp(res); } else if (testType.equals(COMPARE)) { res.setSamplerData("Compare "+getPropertyAsString(COMPAREFILT) + " "
final ArrayList<Attribute> sortedAttrs = new ArrayList<>(size); xmlb.openTag("searchresult"); // $NON-NLS-1$ xmlb.tag("dn", sr.getName()); // $NON-NLS-1$ xmlb.tag("returnedattr",Integer.toString(size)); // $NON-NLS-1$ xmlb.openTag("attributes"); // $NON-NLS-1$ xmlb.tag(attr.getID(),sb); xmlb.closeTag("attributes"); // $NON-NLS-1$ xmlb.closeTag("searchresult"); // $NON-NLS-1$
/** * Close top tag from stack. * * @param tagName name of the tag to close * * @return this * * @throws IllegalArgumentException if the tag names do not match */ public XMLBuffer closeTag(String tagName) { String tag = (String) tags.pop(); if (!tag.equals(tagName)) { throw new IllegalArgumentException( "Trying to close tag: " + tagName + " ; should be " + tag); } endTag(tag); return this; }
/** * Open a tag; save on stack. * * @param tagName name of the tag * @return this */ public XMLBuffer openTag(String tagName) { tags.push(tagName); startTag(tagName); return this; }
/** * Convert the buffer to a string, closing any open tags */ @Override public String toString() { while (!tags.isEmpty()) { endTag((String) tags.pop()); } return sb.toString(); } }