001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * LGPL Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005-2006 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t.connector;
032:
033: import java.io.*;
034: import java.nio.*;
035: import java.nio.channels.*;
036: import java.util.*;
037:
038: import de.ug2t.kernel.*;
039: import de.ug2t.xmlScript.*;
040:
041: public class CoXmlParameterWriter {
042: private static final String pem_body = "<?xml version='1.0' encoding='ISO-8859-1'?>\n<Parameter_List>\n$BODY</Parameter_List>";
043: private static final String pem_cluster = "<Cluster name='$CNAME'>$CBODY</Cluster>\n";
044: private static final String pem_par = "<Parameter name = '$PNAME' value = '$PVALUE'/>\n";
045:
046: /**
047: *
048: */
049: public CoXmlParameterWriter() {
050: }
051:
052: public void pcmf_writeSource(ICoXmlParameterGetter xPg,
053: String xSource, String xFileName) throws Exception {
054: String l_ret = null;
055: StringBuffer l_cl = new StringBuffer();
056: if (xPg == null)
057: xPg = new CoXmlParameterGetter();
058:
059: xPg.pcmf_addSource(xSource);
060:
061: synchronized (xPg) {
062: Iterator l_cit = xPg.pcmf_getClusterKeys(xSource);
063: while (l_cit.hasNext())
064: l_cl.append(this .pcmf_addCluster(xSource, l_cit.next()
065: .toString(), xPg));
066:
067: l_ret = KeTools.pcmf_stringSingleSubst(
068: CoXmlParameterWriter.pem_body, "$BODY", l_cl
069: .toString());
070:
071: FileOutputStream l_fo = new FileOutputStream(KeEnvironment
072: .pcmf_buildPath(xFileName));
073: FileChannel l_channel = l_fo.getChannel();
074: CharBuffer l_buffer = CharBuffer.wrap(l_ret.toCharArray());
075: l_channel.write(KeEnvironment.pcmf_getCharacterSetObject()
076: .encode(l_buffer));
077: l_fo.flush();
078: l_fo.close();
079: }
080: }
081:
082: public void pcmf_deleteSource(ICoXmlParameterGetter xPg,
083: String xSource) {
084: synchronized (xPg) {
085: xPg.pcmf_removeSource(xSource);
086: new File(KeEnvironment.pcmf_buildPath(xSource)).delete();
087: }
088: }
089:
090: private String pcmf_addCluster(String xSource, String xCluster,
091: ICoXmlParameterGetter xPg) {
092: String l_ret = null;
093: StringBuffer l_param = new StringBuffer();
094: Iterator l_cit = xPg.pcmf_getKeys(xSource, xCluster);
095: while (l_cit.hasNext())
096: l_param.append(this .pcmf_addValue(xSource, xCluster, l_cit
097: .next().toString(), xPg));
098:
099: l_ret = KeTools.pcmf_stringSingleSubst(
100: CoXmlParameterWriter.pem_cluster, "$CNAME", xCluster);
101: l_ret = KeTools.pcmf_stringSingleSubst(l_ret, "$CBODY", l_param
102: .toString());
103: return (l_ret);
104: }
105:
106: private String pcmf_addValue(String xSource, String xCluster,
107: String xKey, ICoXmlParameterGetter xPg) {
108: String l_ret = CoXmlParameterWriter.pem_par;
109: l_ret = KeTools.pcmf_stringSingleSubst(l_ret, "$PNAME", xKey);
110: l_ret = KeTools.pcmf_stringSingleSubst(l_ret, "$PVALUE",
111: ScXmlScript.pcmf_filterSigns(xPg.pcmf_getParameter(
112: xSource, xCluster, xKey).toString()));
113:
114: return (l_ret);
115: }
116: }
|