use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.
the class HtmlTransaction method generateWsdlType.
/* (non-Javadoc)
* @see com.twinsoft.convertigo.beans.core.Transaction#generateWsdlType(org.w3c.dom.Document)
*/
@Override
public String generateWsdlType(Document document) throws Exception {
HtmlConnector connector = (HtmlConnector) getParent();
String prefix = getXsdTypePrefix();
// First regenerates wsdltype for default transaction : will contains all types!!
if (!isDefault) {
HtmlTransaction defaultTransaction = (HtmlTransaction) connector.getDefaultTransaction();
defaultTransaction.generateWsdlType(document);
defaultTransaction.hasChanged = true;
}
// Retrieve extraction rules schemas
List<HtmlScreenClass> screenClasses = connector.getAllScreenClasses();
Map<String, ScreenClass> ht = new HashMap<String, ScreenClass>(screenClasses.size());
String normalizedScreenClassName;
int i;
for (ScreenClass screenClass : screenClasses) {
normalizedScreenClassName = StringUtils.normalize(screenClass.getName());
ht.put(normalizedScreenClassName, screenClass);
}
Map<String, String> names = new HashMap<String, String>();
Map<String, String> types = new HashMap<String, String>();
List<String> schemas = new LinkedList<String>();
screenClass = connector.getDefaultScreenClass();
if (screenClass != null) {
addExtractionRuleShemas(names, types, schemas, screenClass);
}
// Retrieve statements schemas
for (Statement statement : getStatements()) {
addStatementSchemas(schemas, statement);
}
// Construct transaction schema
String transactionName = StringUtils.normalize(prefix + getName(), true) + "Response";
String schema = "<?xml version=\"1.0\" encoding=\"" + getEncodingCharSet() + "\" ?>\n";
schema += "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n";
String all, obSchema;
all = "";
for (i = 0; i < schemas.size(); i++) {
obSchema = schemas.get(i);
all += obSchema;
}
if (isDefault) {
String group = "";
String groupName = StringUtils.normalize(connector.getName(), true) + "Types";
group += "<xsd:group name=\"" + groupName + "\">\n";
group += "<xsd:sequence>\n";
group += all;
group += "</xsd:sequence>\n";
group += "</xsd:group>\n";
schema += "<xsd:complexType name=\"" + transactionName + "\">\n";
schema += "<xsd:sequence>\n";
schema += "<xsd:element minOccurs=\"0\" maxOccurs=\"1\" name=\"error\" type=\"p_ns:ConvertigoError\"/>\n";
schema += "<xsd:group minOccurs=\"0\" maxOccurs=\"1\" ref=\"p_ns:" + groupName + "\"/>\n";
schema += "</xsd:sequence>\n";
schema += "</xsd:complexType>\n";
schema += group;
for (Enumeration<String> e = Collections.enumeration(types.keySet()); e.hasMoreElements(); ) {
String typeSchema = (String) types.get(e.nextElement());
schema += typeSchema;
}
} else {
schema += "<xsd:complexType name=\"" + transactionName + "\">\n";
schema += "<xsd:sequence>\n";
schema += "<xsd:element minOccurs=\"0\" maxOccurs=\"1\" name=\"error\" type=\"p_ns:ConvertigoError\"/>\n";
schema += all;
schema += "</xsd:sequence>\n";
schema += "</xsd:complexType>\n";
}
schema += "</xsd:schema>\n";
String prettyPrintedText = XMLUtils.prettyPrintDOM(schema);
int index = prettyPrintedText.indexOf("<xsd:schema") + "<xsd:schema".length();
index = prettyPrintedText.indexOf('\n', index);
prettyPrintedText = prettyPrintedText.substring(index + 1);
prettyPrintedText = prettyPrintedText.substring(0, prettyPrintedText.indexOf("</xsd:schema>"));
// prettyPrintedText = removeTab(prettyPrintedText);
return prettyPrintedText;
}
use of com.twinsoft.convertigo.beans.connectors.HtmlConnector in project convertigo by convertigo.
the class HtmlTransaction method migrateToXsdTypes.
@Override
public String migrateToXsdTypes() {
String xsdTypes = null;
try {
// Retrieve backup wsdlTypes
String backupWsdlTypes = getBackupWsdlTypes();
if (backupWsdlTypes != null) {
String types = backupWsdlTypes;
if (isDefault) {
/* Generate again : correct bug of ref in group */
types = generateWsdlType(null);
if (!isPublicAccessibility()) {
HtmlConnector connector = (HtmlConnector) getParent();
String prefix = (connector.isDefault ? "" : connector.getName() + "__");
String transactionName = StringUtils.normalize(prefix + getName(), true) + "Response";
/* remove complexType for transaction*/
int i = types.indexOf("<xsd:complexType name=\"" + transactionName + "\">");
if (i != -1) {
int j = types.indexOf("</xsd:complexType>", i);
if (j != -1)
types = types.substring(0, i) + types.substring(j + "</xsd:complexType>\n".length());
}
}
}
// Replace xxxResponse by yyy__xxxResponseData
StringEx sx = new StringEx(types);
sx.replace("\"" + getName() + "Response\"", "\"" + getXsdTypePrefix() + getName() + "ResponseData\"");
sx.replace(":" + getName() + "Response\"", ":" + getXsdTypePrefix() + getName() + "ResponseData\"");
sx.replace("__" + getName() + "Response\"", "__" + getName() + "ResponseData\"");
sx.replaceAll("tns:", getProject().getName() + "_ns:");
xsdTypes = generateXsdRequestData() + " " + sx.toString();
}
} catch (Exception e) {
Engine.logBeans.warn("Unable to migrate to XSD types for requestable \"" + getName() + "\"", e);
}
return xsdTypes;
}
Aggregations