Search in sources :

Example 1 with X_EXP_ProcessorParameter

use of org.compiere.model.X_EXP_ProcessorParameter in project adempiere by adempiere.

the class TopicExportProcessor method process.

/**
	 * 
	 */
public void process(Properties ctx, MEXPProcessor expProcessor, Document document, Trx trx) throws Exception {
    String host = expProcessor.getHost();
    int port = expProcessor.getPort();
    String account = expProcessor.getAccount();
    String password = expProcessor.getPasswordInfo();
    String protocol = null;
    String topicName = "";
    String clientID = null;
    String timeToLiveStr = null;
    int timeToLive = 10000;
    boolean isDeliveryModePersistent = true;
    // Read all processor parameters and set them!        
    X_EXP_ProcessorParameter[] processorParameters = expProcessor.getEXP_ProcessorParameters(trx.getTrxName());
    if (processorParameters != null && processorParameters.length > 0) {
        for (int i = 0; i < processorParameters.length; i++) {
            log.info("ProcesParameter          Value = " + processorParameters[i].getValue());
            log.info("ProcesParameter ParameterValue = " + processorParameters[i].getParameterValue());
            if (processorParameters[i].getValue().equals("topicName")) {
                topicName = processorParameters[i].getParameterValue();
            } else if (processorParameters[i].getValue().equals("protocol")) {
                protocol = processorParameters[i].getParameterValue();
            } else if (processorParameters[i].getValue().equals("clientID")) {
                clientID = processorParameters[i].getParameterValue();
            } else if (processorParameters[i].getValue().equals("timeToLive")) {
                timeToLiveStr = processorParameters[i].getParameterValue();
                timeToLive = Integer.parseInt(timeToLiveStr);
            } else if (processorParameters[i].getValue().equals("isDeliveryModePersistent")) {
                isDeliveryModePersistent = Boolean.parseBoolean(processorParameters[i].getParameterValue());
            } else {
            // Some other mandatory parameter here
            }
        }
    }
    if (topicName == null || topicName.length() == 0) {
        throw new Exception("Missing " + X_EXP_ProcessorParameter.Table_Name + " with key 'topicName'!");
    }
    if (protocol == null || protocol.length() == 0) {
        throw new Exception("Missing " + X_EXP_ProcessorParameter.Table_Name + " with key 'protocol'!");
    }
    if (clientID == null || clientID.length() == 0) {
        throw new Exception("Missing " + X_EXP_ProcessorParameter.Table_Name + " with key 'clientID'!");
    }
    if (timeToLiveStr == null || timeToLiveStr.length() == 0) {
        throw new Exception("Missing " + X_EXP_ProcessorParameter.Table_Name + " with key 'timeToLive'!");
    }
    // Construct Transformer Factory and Transformer
    TransformerFactory tranFactory = TransformerFactory.newInstance();
    String jVersion = System.getProperty("java.version");
    if (jVersion.startsWith("1.5.0"))
        tranFactory.setAttribute("indent-number", Integer.valueOf(1));
    Transformer aTransformer = tranFactory.newTransformer();
    aTransformer.setOutputProperty(OutputKeys.INDENT, "yes");
    Source src = new DOMSource(document);
    // =================================== Write to String
    Writer writer = new StringWriter();
    Result dest2 = new StreamResult(writer);
    aTransformer.transform(src, dest2);
    sendJMSMessage(host, port, writer.toString(), protocol, topicName, clientID, account, password, timeToLive, isDeliveryModePersistent);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) X_EXP_ProcessorParameter(org.compiere.model.X_EXP_ProcessorParameter) JMSException(javax.jms.JMSException) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) StringWriter(java.io.StringWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 2 with X_EXP_ProcessorParameter

use of org.compiere.model.X_EXP_ProcessorParameter in project adempiere by adempiere.

the class HDDExportProcessor method process.

public void process(Properties ctx, MEXPProcessor expProcessor, Document document, Trx trx) throws Exception {
    //String host 	= expProcessor.getHost();
    //int port 		= expProcessor.getPort();
    //String account 	= expProcessor.getAccount();
    //String password = expProcessor.getPasswordInfo();
    String fileName = "";
    String folder = "";
    // Read all processor parameters and set them!        
    X_EXP_ProcessorParameter[] processorParameters = expProcessor.getEXP_ProcessorParameters(trx.getTrxName());
    if (processorParameters != null && processorParameters.length > 0) {
        for (int i = 0; i < processorParameters.length; i++) {
            // One special parameter which will be used for remote folder name. 
            // Or could add flag to ProcessorParameters table which will distinguish between 
            // connection parameters and FTP Upload parameters.
            log.info("ProcesParameter          Value = " + processorParameters[i].getValue());
            log.info("ProcesParameter ParameterValue = " + processorParameters[i].getParameterValue());
            if (processorParameters[i].getValue().equals("fileName")) {
                fileName = processorParameters[i].getParameterValue();
            } else if (processorParameters[i].getValue().equals("folder")) {
                folder = processorParameters[i].getParameterValue();
            }
        }
    }
    if (fileName == null || fileName.length() == 0) {
        throw new Exception("Missing EXP_ProcessorParameter with key 'fileName'!");
    }
    // Save the document to the disk file
    TransformerFactory tranFactory = TransformerFactory.newInstance();
    tranFactory.setAttribute("indent-number", Integer.valueOf(1));
    Transformer aTransformer = tranFactory.newTransformer();
    aTransformer.setOutputProperty(OutputKeys.INDENT, "yes");
    Source src = new DOMSource(document);
    // =================================== Write to String
    Writer writer = new StringWriter();
    Result dest2 = new StreamResult(writer);
    aTransformer.transform(src, dest2);
    System.err.println(writer.toString());
    // =================================== Write to Disk
    try {
        Result dest = new StreamResult(new File(folder + fileName));
        aTransformer.transform(src, dest);
        writer.close();
    } catch (TransformerException ex) {
        ex.printStackTrace();
        throw ex;
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) X_EXP_ProcessorParameter(org.compiere.model.X_EXP_ProcessorParameter) TransformerException(javax.xml.transform.TransformerException) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) StringWriter(java.io.StringWriter) File(java.io.File) StringWriter(java.io.StringWriter) Writer(java.io.Writer) TransformerException(javax.xml.transform.TransformerException)

Aggregations

StringWriter (java.io.StringWriter)2 Writer (java.io.Writer)2 Result (javax.xml.transform.Result)2 Source (javax.xml.transform.Source)2 Transformer (javax.xml.transform.Transformer)2 TransformerFactory (javax.xml.transform.TransformerFactory)2 DOMSource (javax.xml.transform.dom.DOMSource)2 StreamResult (javax.xml.transform.stream.StreamResult)2 X_EXP_ProcessorParameter (org.compiere.model.X_EXP_ProcessorParameter)2 File (java.io.File)1 JMSException (javax.jms.JMSException)1 TransformerException (javax.xml.transform.TransformerException)1