Java tutorial
// Description: Java 8 XML Message message formatter for CFAsterisk /* * Code Factory Asterisk 11 Configuration Model * * Copyright (c) 2014-2015 Mark Sobkow * * This program is available as free software under the GNU GPL v3, or * under a commercial license from Mark Sobkow. For commercial licensing * details, please contact msobkow@sasktel.net. * * Under the terms of the GPL: * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskXMsg; import java.math.*; import java.sql.*; import java.text.*; import java.util.*; import org.apache.commons.codec.binary.Base64; import org.xml.sax.*; import net.sourceforge.msscodefactory.cflib.v2_3.CFLib.*; import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurity.*; import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternet.*; import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsterisk.*; import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurityObj.*; import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternetObj.*; import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskObj.*; /* * CFAsteriskXMsgSchemaMessageFormatter XML message formatter * for CFAsterisk. */ public class CFAsteriskXMsgSchemaMessageFormatter { private String messageNamespace = "CFAsterisk"; public String getMessageNamespace() { return (messageNamespace); } public void setMessageNamespace(String value) { final String S_ProcName = "setMessageNamespace"; if ((value == null) || (value.length() <= 0)) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1, "value"); } messageNamespace = new String(value); } public CFAsteriskXMsgSchemaMessageFormatter() { } public static String formatRqstXmlPreamble() { final String retval = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<CFAsteriskRqst\n" + "\t\txmlns=\"uri://xsd/cfasteriskrqst\"\n" + "\t\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "\t\txmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" + "\t\txsi:schemaLocation=\"uri://xsd/cfasteriskrqst file://xsd/cfasterisk-24-rqst.xsd\" >"; return (retval); } public static String formatRqstXmlPostamble() { final String retval = "</CFAsteriskRqst>\n"; return (retval); } public String formatRspnXmlPreamble() { final String retval = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<" + messageNamespace + "Rspn\n" + "\t\txmlns=\"uri://xsd/" + messageNamespace.toLowerCase() + "rspn\"\n" + "\t\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + "\t\txmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" + "\t\txsi:schemaLocation=\"uri://xsd/" + messageNamespace.toLowerCase() + "rspn file://xsd/" + messageNamespace.toLowerCase() + "-24-rspn.xsd\" >"; return (retval); } public String formatRspnXmlPostamble() { final String retval = "</" + messageNamespace + "Rspn>\n"; return (retval); } public static String formatRspnNoDataFound() { String retval = "<RspnNoDataFound />"; return (retval); } public static String formatRspnException(String separator, Throwable t) { String retval = "<RspnException " + CFLibXmlUtil.formatRequiredXmlString(null, "Name", t.getClass().getName()) + CFLibXmlUtil.formatRequiredXmlString(separator, "Message", t.getMessage()) + " />"; return (retval); } public static String formatRqstFileImport(String separator, String fileName, String fileContents) { String retval = "<RqstFileImport " + CFLibXmlUtil.formatRequiredXmlString(null, "FileName", fileName) + CFLibXmlUtil.formatRequiredXmlString(separator, "FileContents", fileContents) + " />"; return (retval); } public static String formatRqstLogIn(String separator, String loginId, String deviceName, byte devEncPWHash[], String clusterName, String tenantName) { String retval = "<RqstLogIn " + CFLibXmlUtil.formatRequiredXmlString(null, "LoginId", loginId) + CFLibXmlUtil.formatRequiredXmlString(separator, "DeviceName", deviceName) + CFLibXmlUtil.formatRequiredBlob(separator, "DevEncPWHash", devEncPWHash) + CFLibXmlUtil.formatRequiredXmlString(separator, "ClusterName", clusterName) + CFLibXmlUtil.formatRequiredXmlString(separator, "TenantName", tenantName) + " />"; return (retval); } public static String formatRqstLogOut(String separator, UUID secSessionId) { String retval = "<RqstLogOut " + CFLibXmlUtil.formatRequiredXmlString(null, "SecSessionId", secSessionId.toString()) + " />"; return (retval); } public static String formatRspnFileLoaded(String separator, String logContents) { String retval = "<RspnFileLoaded " + CFLibXmlUtil.formatRequiredXmlString(null, "LogContents", logContents) + " />"; return (retval); } public static String formatRspnServerProcExecuted(String separator, boolean dataChanged) { String retval = "<RspnServerProcExecuted " + CFLibXmlUtil.formatRequiredBoolean(null, "DataChanged", dataChanged) + " />"; return (retval); } public static String formatRspnLoggedIn(String separator, long clusterId, String clusterName, long tenantId, String tenantName, UUID secUserId, String secUserName, UUID secSessionId) { String retval = "<RspnLoggedIn " + CFLibXmlUtil.formatRequiredInt64(null, "ClusterId", clusterId) + CFLibXmlUtil.formatRequiredXmlString(separator, "ClusterName", clusterName) + CFLibXmlUtil.formatRequiredInt64(separator, "TenantId", tenantId) + CFLibXmlUtil.formatRequiredXmlString(separator, "TenantName", tenantName) + CFLibXmlUtil.formatRequiredXmlString(separator, "SecUserId", secUserId.toString()) + CFLibXmlUtil.formatRequiredXmlString(separator, "SecUserName", secUserName) + CFLibXmlUtil.formatRequiredXmlString(separator, "SecSessionId", secSessionId.toString()) + " />"; return (retval); } public static String formatRspnLoggedOut(String separator, UUID secSessionId) { String retval = "<RspnLoggedOut " + CFLibXmlUtil.formatRequiredXmlString(null, "SecSessionId", secSessionId.toString()) + " />"; return (retval); } }