The example provided in this document is provided “as-is” to the user and assumes that the user:
PREREQUISITES:
For the sample to work, the Strategy Web JAR files must be accessible by the Java Runtime
Environment. The Strategy Web JAR files can be found under:
Note:
More elaborate programs will require additional library files and are out of the scope of this document.
The WebElementSource and WebElements API can be used to fetch a list of attribute elements to populate in a custom application. Sometimes a list of attribute elements can be quite large so a developer may find it feasible to fetch only a small amount of elements at a time. This is possible to do using the following method:
webElementSource.setBlockCount(10);
When adding the above method to the code, now only the first 10 elements will be returned to the WebElements collection. Sometimes it's necessary for the developer to still know the total amount of elements that are available.
The following sample demonstrates how to get the total count of Elements available event though only a small subset of elements is being fetched at a time:
Java
package customclasses.misc;
import java.util.Enumeration;
import com.Strategy.web.objects.WebAttribute;
import com.Strategy.web.objects.WebAttributeForm;
import com.Strategy.web.objects.WebAttributeForms;
import com.Strategy.web.objects.WebElement;
import com.Strategy.web.objects.WebElementSource;
import com.Strategy.web.objects.WebElements;
import com.Strategy.web.objects.WebIServerSession;
import com.Strategy.web.objects.WebObjectSource;
import com.Strategy.web.objects.WebObjectsException;
import com.Strategy.web.objects.WebObjectsFactory;
import com.Strategy.webapi.EnumDSSXMLAuthModes;
import com.Strategy.webapi.EnumDSSXMLObjectTypes;
public class GetElementsTotalSize {
public static void main(String[] args) throws WebObjectsException {
WebObjectsFactory objectFactory = WebObjectsFactory.getInstance();
WebIServerSession serverSession = objectFactory.getIServerSession();
serverSession.setServerPort(0);
serverSession.setAuthMode(EnumDSSXMLAuthModes.DssXmlAuthStandard);
serverSession.setProjectName("Strategy Tutorial");
serverSession.setLogin("administrator");
serverSession.setPassword("");
serverSession.setServerName("SERVERNAME");
try{
WebObjectSource webObjectSource = serverSession.getFactory().getObjectSource();
//Using the Subcategory attribute from Strategy Tutorial
WebAttribute webAttribute = (WebAttribute)webObjectSource.getObject("8D679D4F11D3E4981000E787EC6DE8A4",EnumDSSXMLObjectTypes.DssXmlTypeAttribute,true);
WebAttributeForms webAttributeForms = webAttribute.getForms();
WebAttributeForm webAttributeForm = null;
String attributesXML = "";
for (int x= 0 ; x < webAttributeForms.size(); x++){
webAttributeForm = webAttributeForms.get(x);
if(webAttributeForm.getUseName().equals("ID"))
attributesXML += "<oi did=\"" + webAttributeForm.getID() + "\"/>";
}
attributesXML = "<fct>" + attributesXML + "</fct>";
WebElementSource webElementSource = serverSession.getFactory().getElementSourceObject();
webElementSource.setObject(webAttribute);
webElementSource.setAttributeFormsXML(attributesXML);
//this will determine how many elements are returned in the fetch
webElementSource.setBlockCount(10);
String resultXML = webElementSource.getElementsXML();
System.out.println("xml: "+ resultXML);
WebElements webElements = webElementSource.getElements();
//this size variable will return 10 because of the block count setting above:
int size = webElements.size();
System.out.println("Size of elements in fetch: "+ size);
//this totalCount will return the total count of elements that are available, which will be 24 in this example:
int totalCount = webElements.getChildUnits().getChildCount();
System.out.println("Total count: "+ totalCount);
//iterating through the collection of elements returned:
Enumeration enumeration = webElements.elements();
while(enumeration.hasMoreElements()){
System.out.println(((WebElement)enumeration.nextElement()).getElementID());
}
System.out.println("done");
}
catch (Exception ee) {
ee.printStackTrace();
}
}
}
CUSTOMIZATION WARNING:
This customization is provided as a convenience to Strategy users and is only directly applicable to the version stated. While this code may apply to other releases directly, Strategy Technical Support makes no guarantees that the code provided will apply to any future or previous builds. In the event of a code change in future builds, Strategy Technical Support makes no guarantee that an updated version of this particular customization will be provided. In the event of a code change in future builds, Strategy may not be able to provide additional code on this matter even though this customization is provided at this time for this specific build. For enhancements to this customization or to incorporate similar functionality into other versions, contact your Account Executive to inquire about Strategy Consulting assistance.