Search in sources :

Example 41 with HtmlConnector

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;
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) HashMap(java.util.HashMap) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) HtmlScreenClass(com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass) ContextAddTextNodeStatement(com.twinsoft.convertigo.beans.statements.ContextAddTextNodeStatement) HTTPStatement(com.twinsoft.convertigo.beans.statements.HTTPStatement) Statement(com.twinsoft.convertigo.beans.core.Statement) HandlerStatement(com.twinsoft.convertigo.beans.statements.HandlerStatement) LinkedList(java.util.LinkedList) HtmlScreenClass(com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass)

Example 42 with HtmlConnector

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;
}
Also used : HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) StringEx(com.twinsoft.util.StringEx) EngineException(com.twinsoft.convertigo.engine.EngineException) EvaluatorException(org.mozilla.javascript.EvaluatorException) JavaScriptException(org.mozilla.javascript.JavaScriptException) IOException(java.io.IOException) ObjectWithSameNameException(com.twinsoft.convertigo.engine.ObjectWithSameNameException)

Aggregations

HtmlConnector (com.twinsoft.convertigo.beans.connectors.HtmlConnector)42 HtmlTransaction (com.twinsoft.convertigo.beans.transactions.HtmlTransaction)14 ScreenClass (com.twinsoft.convertigo.beans.core.ScreenClass)13 EngineException (com.twinsoft.convertigo.engine.EngineException)13 JavelinConnector (com.twinsoft.convertigo.beans.connectors.JavelinConnector)12 Connector (com.twinsoft.convertigo.beans.core.Connector)12 Transaction (com.twinsoft.convertigo.beans.core.Transaction)10 HttpConnector (com.twinsoft.convertigo.beans.connectors.HttpConnector)8 SqlConnector (com.twinsoft.convertigo.beans.connectors.SqlConnector)8 SiteClipperConnector (com.twinsoft.convertigo.beans.connectors.SiteClipperConnector)7 Statement (com.twinsoft.convertigo.beans.core.Statement)7 Document (org.w3c.dom.Document)7 CicsConnector (com.twinsoft.convertigo.beans.connectors.CicsConnector)6 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)6 HandlerStatement (com.twinsoft.convertigo.beans.statements.HandlerStatement)6 List (java.util.List)6 HtmlScreenClass (com.twinsoft.convertigo.beans.screenclasses.HtmlScreenClass)5 ScHandlerStatement (com.twinsoft.convertigo.beans.statements.ScHandlerStatement)5 IOException (java.io.IOException)5 TransformerException (javax.xml.transform.TransformerException)5