Results 1 to 4 of 4
  1. #1
    madhuks is offline Member
    Join Date
    Jul 2010
    Posts
    2
    Rep Power
    0

    Default how to do checking value

    hi,
    in my project...i had used jsp pages..if i enter value in jsp page..it should match with the parameter passed in servlet...and if it is checked it should do process...my project includes xml file..im not getting validated..can any one help me out..here is my code

    login.jsp

    Java Code:
    <td></td>
                            <td><font color="#800000">&nbsp;</font><font color="#800000"><b>Pack Name</b></font><font color="#800000" size="">&nbsp;</font></td>
                            <td><input name="packName" type="text" id="packName"> </td>
                            <td></td>
    login.java

    Java Code:
    package proj;
    
    import java.io.*;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Properties;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.w3c.dom.*;
    import javax.xml.parsers.*;
    import javax.xml.transform.*;
    import javax.xml.transform.dom.*;
    import javax.xml.transform.stream.*;
    
    public class modify extends HttpServlet {
    
        public void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    
            response.setContentType("text/html");
            PrintWriter pw = response.getWriter();
    
            // Assigning the Attributes
            // Getting the values
            String packName = request.getParameter("packName");
            String actStatus = request.getParameter("actStatus");
    
            //Getting Deact Status
            String deactStatus = request.getParameter("deactStatus");
            String deact = "MD";
            String deactStatusStr = deact + deactStatus;
            
            String allowPostPaid = request.getParameter("allowPostPaid");
            String shortCode = request.getParameter("shortCode");
            String actKey = request.getParameter("actKey");
            String deactKey = request.getParameter("deactKey");
            String actSwitch = request.getParameter("actSwitch");
            String deactSuccessSwitch = request.getParameter("deactSuccessSwitch");
            String appMode = request.getParameter("appMode");
            String balCheck = request.getParameter("balCheck");
            String validStatus = request.getParameter("validStatus");
            // psobit = request.getParameter("psobit");
    
            // Getting PSOBit Array
            String[] psobitStatus = request.getParameterValues("psobitStatus");
            String psobitStr = "";
            for (int i = 0; i < psobitStatus.length; i++) {
                if (psobitStr == null) {
                    psobitStr += psobitStatus[i];
                } else {
                    psobitStr += psobitStatus[i];
                }
                //pw.println(str);
            }
    
            String actPSOBit = request.getParameter("actPSOBit");
            String deactPSOBit = request.getParameter("deactPSOBit");
            String actMASKBit = request.getParameter("actMASKBit");
            String deactMASKBit = request.getParameter("deactMASKBit");
            // balrdys = request.getParameter("balrdys");
    
            // Getting Balance Retrieval Days
            String[] lowBalRetryDays = request.getParameterValues("lowBalRetryDays");
            String balrdysStr = "";
            for (int i = 0; i < lowBalRetryDays.length; i++) {
                balrdysStr += lowBalRetryDays[i];
                  if ((i+1) % 2 == 0 ){
                //if ((i+1) % 2 == 0 && i!=lowBalRetryDays.length-1) {
                    balrdysStr += ":";
                }
            }
    
            String alertMsg = request.getParameter("alertMsg");
            // rtryprop = request.getParameter("rtryprop");
    
            // Getting Retry Properties
            String[] retryProp = request.getParameterValues("retryProp");
            String balrtrypropStr = "";
            for (int j = 0; j < retryProp.length; j++) {
                 balrtrypropStr += retryProp[j];
                if ((j+1) % 2 == 0 ) {
                    balrtrypropStr += ":";
                }
            }
    
            // mactprop = request.getParameter("mactprop");
    
            // Getting Multiple Act Properties
            String[] multiActProp = request.getParameterValues("multiActProp");
            String mactpropStr = "";
            for (int k = 0; k < multiActProp.length; k++) {
                   mactpropStr += multiActProp[k];
                if ((k+1) % 2 == 0 ){
                    mactpropStr+=":";
                }
            }
    
            String lowBalMigrate = request.getParameter("lowBalMigrate");
            String msCmdCount = request.getParameter("msCmdCount");
            String multiAct = request.getParameter("multiAct");
            String nullDa = request.getParameter("nullDa");
            String localAccNo = request.getParameter("localAccNo");
            String localUnits = request.getParameter("localUnits");
            String localUnitValid = request.getParameter("localUnitValid");
            String localTrnsCode = request.getParameter("localTrnsCode");
            String stdAccNo = request.getParameter("stdAccNo");
            String stdUnits = request.getParameter("stdUnits");
            String stdUnitValid = request.getParameter("stdUnitValid");
            String stdTrnsCode = request.getParameter("stdTrnsCode");
            String isdAccNo = request.getParameter("isdAccNo");
            String isdUnits = request.getParameter("isdUnits");
            String isdUnitValid = request.getParameter("isdUnitValid");
            String isdTrnsCode = request.getParameter("isdTrnsCode");
            
            //Getting Auto-Renewal Properties
            String[] autoRenewal = request.getParameterValues("autoRenewal");
            String autoRenewalStr = "";
            for (int i = 0; i < autoRenewal.length; i++) {
                autoRenewalStr += autoRenewal[i];
                if ((i + 1) % 2 == 0 &&i!=autoRenewal.length-1) {
                    autoRenewalStr += ":";
                }
            }
            
            //Getting Do Differential Balance Check
            String[] doDiffBalChk = request.getParameterValues("doDiffBalChk");
            String doDiffBalChkStr = "";
            for (int i = 0; i < doDiffBalChk.length; i++) {
                if (doDiffBalChkStr == null) {
                    doDiffBalChkStr += doDiffBalChk[i];
                } else {
                    doDiffBalChkStr += doDiffBalChk[i];
                }
                //pw.println(str);
            }
            
            String diffParams = request.getParameter("diffParams");
            String doBill = request.getParameter("doBill");
    
            //Appending the ChargeID
            String chargeId = request.getParameter("chargeId");
            String s = "NETXCELL LAPU GPRS";
            String chargeIdString = s + " " +chargeId;
    
            String billType = request.getParameter("billType");
            String negtveBalDebit = request.getParameter("negtveBalDebit");
            String mtShortCode = request.getParameter("mtShortCode");
            String debitAmount = request.getParameter("debitAmount");
            String blackListChk = request.getParameter("blackListChk");
            String blackListFilePath = request.getParameter("blackListFilePath");
            String actSuccessMsg = request.getParameter("actSuccessMsg");
            String deactSuccessMsg = request.getParameter("deactSuccessMsg");
            String postPaid = request.getParameter("postPaid");
            String actFailMsg = request.getParameter("actFailMsg");
            String actLowBalMsg = request.getParameter("actLowBalMsg");
            String autoRenewalMsg = request.getParameter("autoRenewalMsg");
            String autoDiffMsg = request.getParameter("autoDiffMsg");
            String malrtMsg = request.getParameter("malrtMsg");
            String suspendMsg = request.getParameter("suspendMsg");
            String stillSuspendMsg = request.getParameter("stillSuspendMsg");
            String retryStopMsg = request.getParameter("retryStopMsg");
            String blackListMsg = request.getParameter("blackListMsg");
            String splFlag = request.getParameter("splFlag");
    
            // Bulding The XML File using DOM
            try {
                DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
                DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
    
                // Creating the path for XML File using Properties
                ServletContext servletContextObj = request.getSession().getServletContext();
                String excelTemplatesPath = servletContextObj.getRealPath("/");
                String filePaths = excelTemplatesPath + File.separator
                        + "config.properties";
                Properties propObj = new Properties();
                propObj.load(new FileInputStream(filePaths));
                String gprsLoginPath = null;
                gprsLoginPath = propObj.getProperty("GPRS_LOGIN_PATH");
                if (gprsLoginPath == null || gprsLoginPath.trim().equals("")) {
                    gprsLoginPath = excelTemplatesPath;
                }
                gprsLoginPath += File.separator + "login.xml";
                java.io.File file = new java.io.File(gprsLoginPath);
                Document doc = null;
                if (file.exists()) {
                    try {
                        doc = docBuilder.parse(file);
                    } catch (Exception ex) {
                        doc = docBuilder.newDocument();
                        Element root = doc.createElement("PACKS");
                        doc.appendChild(root);
                    }
                } else {
                    doc = docBuilder.newDocument();
                    // Creating Root Tag
                    Element root = doc.createElement("PACKS");
                    doc.appendChild(root);
                }
    
                // creating a new instance of a DOM to build a DOM tree.
                // Document doc = docBuilder.newDocument();
                createXmlTree(file, doc, packName, actStatus, deactStatusStr, allowPostPaid, shortCode, actKey, deactKey, actSwitch, deactSuccessSwitch, appMode, balCheck, validStatus, psobitStr, actPSOBit, deactPSOBit, actMASKBit, deactMASKBit, balrdysStr, alertMsg, balrtrypropStr, mactpropStr, lowBalMigrate, msCmdCount, multiAct, nullDa, localAccNo, localUnits, localUnitValid, localTrnsCode, stdAccNo, stdUnits, stdUnitValid, stdTrnsCode, isdAccNo, isdUnits, isdUnitValid, isdTrnsCode, autoRenewalStr, doDiffBalChkStr, diffParams, doBill, chargeIdString, billType, negtveBalDebit, mtShortCode, debitAmount, blackListChk, blackListFilePath, actSuccessMsg, deactSuccessMsg, postPaid, actFailMsg, actLowBalMsg, autoRenewalMsg, autoDiffMsg, malrtMsg, suspendMsg, stillSuspendMsg, retryStopMsg, blackListMsg, splFlag);
                pw.println("<b>Xml File Updated Successfully</b>");
            } catch (Exception e) {
                System.out.println(e);
                e.printStackTrace();
            }
        }
    
        private void createXmlTree(java.io.File file, Document doc, String packName, String actStatus, String deactStatusStr, String allowPostPaid, String shortCode, String actKey, String deactKey, String actSwitch, String deactSuccessSwitch, String appMode, String balCheck, String validStatus, String psobitStr, String actPSOBit, String deactPSOBit, String actMASKBit, String deactMASKBit, String balrdysStr, String alertMsg, String balrtrypropStr, String mactpropStr, String lowBalMigrate, String msCmdCount, String multiAct, String nullDa, String localAccNo, String localUnits, String localUnitValid, String localTrnsCode, String stdAccNo, String stdUnits, String stdUnitValid, String stdTrnsCode, String isdAccNo, String isdUnits, String isdUnitValid, String isdTrnsCode, String autoRenewalStr, String doDiffBalChkStr, String diffParams, String doBill, String chargeIdString, String billType, String negtveBalDebit, String mtShortCode, String debitAmount, String blackListChk, String blackListFilePath, String actSuccessMsg, String deactSuccessMsg, String postPaid, String actFailMsg, String actLowBalMsg, String autoRenewalMsg, String autoDiffMsg, String malrtMsg, String suspendMsg, String stillSuspendMsg, String retryStopMsg, String blackListMsg, String splFlag)
                throws Exception {
            
            // This method creates an element node
            Node node = doc.getFirstChild();
            NodeList list1 = doc.getElementsByTagName(actStatus);
            NodeList list = doc.getElementsByTagName("GENERAL");
            NodeList listDedAct = doc.getElementsByTagName("DEDICATED_ACCOUNT");
            NodeList listDedActLocal = doc.getElementsByTagName("DED_ACC_LOCAL");
            NodeList listDedActStd = doc.getElementsByTagName("DED_ACC_STD");
            NodeList listDedActIsd = doc.getElementsByTagName("DED_ACC_ISD");
            NodeList listAuto = doc.getElementsByTagName("AUTORENEWAL");
            NodeList listDiff = doc.getElementsByTagName("DIFFERENTIAL");
            NodeList listBill = doc.getElementsByTagName("BILLING");
            NodeList listBlckList = doc.getElementsByTagName("BLACK_LIST");
            NodeList listMsg = doc.getElementsByTagName("MESSAGES");
    
             //For General Properties
            Node usernode = null;
    
            for (int j = 0; j < list.getLength(); j++) {
                usernode = list.item(j);
                 System.out.println("hello");
                System.out.println(usernode.getNodeName());           
            }
            
            System.out.println(usernode.getNodeName());
            NodeList usernodeList = usernode.getChildNodes();
            for (int i = 0; i < usernodeList.getLength(); i++) {
                Node userNodeSub = usernodeList.item(i);
                if (userNodeSub.getNodeName().equalsIgnoreCase("PACK_NAME")) {
                    userNodeSub.setTextContent(packName);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("ACT_STATUS")) {
                    userNodeSub.setTextContent(actStatus);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("DEACT_STATUS")) {
                    userNodeSub.setTextContent(deactStatusStr);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("ALLOW_POSTPAID")) {
                    userNodeSub.setTextContent(allowPostPaid);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("SHORT_CODE")) {
                    userNodeSub.setTextContent(shortCode);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("ACT_KEYWORD")) {
                    userNodeSub.setTextContent(actKey);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("DEACT_KEYWORD")) {
                    userNodeSub.setTextContent(deactKey);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("ACT_SUCCESS_SWITCHACTIVATE")) {
                    userNodeSub.setTextContent(actSwitch);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("DEACT_SUCCESS_SWITCHACTIVATE")) {
                    userNodeSub.setTextContent(deactSuccessSwitch);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("ONLY_BILLING")) {
                    userNodeSub.setTextContent(appMode);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("BAL_TO_CHK")) {
                    userNodeSub.setTextContent(balCheck);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("VALIDITY")) {
                    userNodeSub.setTextContent(validStatus);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("SET_PSOBIT")) {
                    userNodeSub.setTextContent(psobitStr);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("ACT_PSOBIT")) {
                    userNodeSub.setTextContent(actPSOBit);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("DEACT_PSOBIT")) {
                    userNodeSub.setTextContent(deactPSOBit);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("ACT_MASKBIT")) {
                    userNodeSub.setTextContent(actMASKBit);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("DEACT_MASKBIT")) {
                    userNodeSub.setTextContent(deactMASKBit);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("LOW_BAL_RETRY_DAYS")) {
                    userNodeSub.setTextContent(balrdysStr);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("ALERT_MSG_TIME")) {
                    userNodeSub.setTextContent(alertMsg);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("RETRY_PROPERTIES")) {
                    userNodeSub.setTextContent(balrtrypropStr);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("MULTIPLEACT_PROPERTIES")) {
                    userNodeSub.setTextContent(mactpropStr);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("LOW_BAL_MIGRATE_AGRS")) {
                    userNodeSub.setTextContent(lowBalMigrate);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("MINSAT_COMMAND_ERROR_RESP_RETRY_COUNT")) {
                    userNodeSub.setTextContent(msCmdCount);
                } else if (userNodeSub.getNodeName().equalsIgnoreCase("SPECIAL_FLAGS")) {
                    userNodeSub.setTextContent(splFlag);
                }
            }
    
            //For Dedicated Account Properties
            Node userNodeDed = null;
            for (int a = 0; a < listDedAct.getLength(); a++) {
                userNodeDed = listDedAct.item(a);
            }
            NodeList userNodeDedList = userNodeDed.getChildNodes();
            for (int i = 0; i < userNodeDedList.getLength(); i++) {
                Node userNodeDedSub = userNodeDedList.item(i);
    
                if (userNodeDedSub.getNodeName().equalsIgnoreCase("ALLOW_MULTILE_ACT")) {
                    userNodeDedSub.setTextContent(multiAct);
                } else if (userNodeDedSub.getNodeName().equalsIgnoreCase("NULLIFY_DA")) {
                    userNodeDedSub.setTextContent(nullDa);
                }
            }
    
            //For Dedicated Account Local Properties
            Node userNodeDedLocal = null;
            for (int a = 0; a < listDedActLocal.getLength(); a++) {
                userNodeDedLocal = listDedActLocal.item(a);
            }
            NodeList userNodeDedLocalList = userNodeDedLocal.getChildNodes();
            for (int i = 0; i < userNodeDedLocalList.getLength(); i++) {
                Node userNodeDedLocalSub = userNodeDedLocalList.item(i);
    
                if (userNodeDedLocalSub.getNodeName().equalsIgnoreCase("ACC_NO")) {
                    userNodeDedLocalSub.setTextContent(localAccNo);
                } else if (userNodeDedLocalSub.getNodeName().equalsIgnoreCase("UNITS_TO_POST")) {
                    userNodeDedLocalSub.setTextContent(localUnits);
                } else if (userNodeDedLocalSub.getNodeName().equalsIgnoreCase("VALIDITY")) {
                    userNodeDedLocalSub.setTextContent(localUnitValid);
                } else if (userNodeDedLocalSub.getNodeName().equalsIgnoreCase("TRANSACTION_CODE")) {
                    userNodeDedLocalSub.setTextContent(localTrnsCode);
                }
            }
    
            //For Dedicated Account Std Properties
            Node userNodeDedStd = null;
            for (int a = 0; a < listDedActStd.getLength(); a++) {
                userNodeDedStd = listDedActStd.item(a);
            }
            NodeList userNodeDedStdList = userNodeDedStd.getChildNodes();
            for (int i = 0; i < userNodeDedStdList.getLength(); i++) {
                Node userNodeDedStdSub = userNodeDedStdList.item(i);
    
                if (userNodeDedStdSub.getNodeName().equalsIgnoreCase("ACC_NO")) {
                    userNodeDedStdSub.setTextContent(stdAccNo);
                } else if (userNodeDedStdSub.getNodeName().equalsIgnoreCase("UNITS_TO_POST")) {
                    userNodeDedStdSub.setTextContent(stdUnits);
                } else if (userNodeDedStdSub.getNodeName().equalsIgnoreCase("VALIDITY")) {
                    userNodeDedStdSub.setTextContent(stdUnitValid);
                } else if (userNodeDedStdSub.getNodeName().equalsIgnoreCase("TRANSACTION_CODE")) {
                    userNodeDedStdSub.setTextContent(stdTrnsCode);
                }
            }
    
            //For Dedicated Account Isd Properties
            Node userNodeDedIsd = null;
            for (int a = 0; a < listDedActIsd.getLength(); a++) {
                userNodeDedIsd = listDedActIsd.item(a);
            }
            NodeList userNodeDedIsdList = userNodeDedIsd.getChildNodes();
            for (int i = 0; i < userNodeDedIsdList.getLength(); i++) {
                Node userNodeDedIsdSub = userNodeDedIsdList.item(i);
    
                if (userNodeDedIsdSub.getNodeName().equalsIgnoreCase("ACC_NO")) {
                    userNodeDedIsdSub.setTextContent(isdAccNo);
                } else if (userNodeDedIsdSub.getNodeName().equalsIgnoreCase("UNITS_TO_POST")) {
                    userNodeDedIsdSub.setTextContent(isdUnits);
                } else if (userNodeDedIsdSub.getNodeName().equalsIgnoreCase("VALIDITY")) {
                    userNodeDedIsdSub.setTextContent(isdUnitValid);
                } else if (userNodeDedIsdSub.getNodeName().equalsIgnoreCase("TRANSACTION_CODE")) {
                    userNodeDedIsdSub.setTextContent(isdTrnsCode);
                }
            }
    
            //For Auto-Renewal Properties
            Node userNodeDedAuto = null;
            for (int a = 0; a < listAuto.getLength(); a++) {
                userNodeDedAuto = listAuto.item(a);
            }
            if (userNodeDedAuto != null) {
                NodeList userNodeDedAutoList = userNodeDedAuto.getChildNodes();
                for (int i = 0; i < userNodeDedAutoList.getLength(); i++) {
                    Node userNodeDedAutoSub = userNodeDedAutoList.item(i);
    
                    if (userNodeDedAutoSub.getNodeName().equalsIgnoreCase("DO_AUTORENEWAL")) {
                        userNodeDedAutoSub.setTextContent(autoRenewalStr);
                    }
                }
            }
            //For Billing Properties
            Node userNodeDedDiff = null;
            for (int a = 0; a < listDiff.getLength(); a++) {
                userNodeDedDiff = listDiff.item(a);
            }
            if (userNodeDedDiff != null) {
                NodeList userNodeDedDiffList = userNodeDedDiff.getChildNodes();
                for (int i = 0; i < userNodeDedDiffList.getLength(); i++) {
                    Node userNodeDedDiffSub = userNodeDedDiffList.item(i);
    
                    if (userNodeDedDiffSub.getNodeName().equalsIgnoreCase("DO_DIFFERENTIAL_BAL_CHK")) {
                        userNodeDedDiffSub.setTextContent(doDiffBalChkStr);
                    } else if (userNodeDedDiffSub.getNodeName().equalsIgnoreCase("DIFF_PARAMAS")) {
                        userNodeDedDiffSub.setTextContent(diffParams);
                    }
                }
            }
            //For Billing Properties
            Node userNodeDedBill = null;
            for (int a = 0; a < listBill.getLength(); a++) {
                userNodeDedBill = listBill.item(a);
            }
            if (userNodeDedBill != null) {
                NodeList userNodeDedBillList = userNodeDedBill.getChildNodes();
                for (int i = 0; i < userNodeDedBillList.getLength(); i++) {
                    Node userNodeDedBillSub = userNodeDedBillList.item(i);
    
                    if (userNodeDedBillSub.getNodeName().equalsIgnoreCase("DO_BILLING")) {
                        userNodeDedBillSub.setTextContent(doBill);
                    } else if (userNodeDedBillSub.getNodeName().equalsIgnoreCase("CHARGE_ID")) {
                        userNodeDedBillSub.setTextContent(chargeIdString);
                    } else if (userNodeDedBillSub.getNodeName().equalsIgnoreCase("TYPE_OF_BILLING")) {
                        userNodeDedBillSub.setTextContent(billType);
                    } else if (userNodeDedBillSub.getNodeName().equalsIgnoreCase("NEGATIVE_BALANCE_DEBIT")) {
                        userNodeDedBillSub.setTextContent(negtveBalDebit);
                    } else if (userNodeDedBillSub.getNodeName().equalsIgnoreCase("MT_SHORTCODE")) {
                        userNodeDedBillSub.setTextContent(mtShortCode);
                    } else if (userNodeDedBillSub.getNodeName().equalsIgnoreCase("DEBIT_AMOUNT")) {
                        userNodeDedBillSub.setTextContent(debitAmount);
                    }
                }
            }
            //For Black-List Properties
            Node userNodeDedBlck = null;
    
            for (int a = 0; a < listBlckList.getLength(); a++) {
                userNodeDedBlck = listBlckList.item(a);
            }
            if (userNodeDedBlck != null) {
                NodeList userNodeDedBlckList = userNodeDedBlck.getChildNodes();
                for (int i = 0; i < userNodeDedBlckList.getLength(); i++) {
                    Node userNodeDedBlckSub = userNodeDedBlckList.item(i);
    
                    if (userNodeDedBlckSub.getNodeName().equalsIgnoreCase("DO_BLACK_LIST_CHK")) {
                        userNodeDedBlckSub.setTextContent(blackListChk);
                    } else if (userNodeDedBlckSub.getNodeName().equalsIgnoreCase("BLACK_LIST_FILE_PATH")) {
                        userNodeDedBlckSub.setTextContent(blackListFilePath);
                    }
                }
            }
            //For Message Properties
            Node userNodeMsg = null;
            for (int a = 0; a < listMsg.getLength(); a++) {
                userNodeMsg = listMsg.item(a);
            }
            if (userNodeMsg != null) {
                NodeList userNodeMsgList = userNodeMsg.getChildNodes();
                for (int i = 0; i < userNodeMsgList.getLength(); i++) {
                    Node userNodeMsgSub = userNodeMsgList.item(i);
    
                    if (userNodeMsgSub.getNodeName().equalsIgnoreCase("ACT_SUCCESS_MESSAGE")) {
                        userNodeMsgSub.setTextContent(actSuccessMsg);
                    } else if (userNodeMsgSub.getNodeName().equalsIgnoreCase("DEACT_SUCCESS_MESSAGE")) {
                        userNodeMsgSub.setTextContent(deactSuccessMsg);
                    } else if (userNodeMsgSub.getNodeName().equalsIgnoreCase("POSTPAID")) {
                        userNodeMsgSub.setTextContent(postPaid);
                    } else if (userNodeMsgSub.getNodeName().equalsIgnoreCase("ACT_FAIL_MESSAGE")) {
                        userNodeMsgSub.setTextContent(actFailMsg);
                    } else if (userNodeMsgSub.getNodeName().equalsIgnoreCase("ACT_LOWBAL_MESSAGE")) {
                        userNodeMsgSub.setTextContent(actLowBalMsg);
                    } else if (userNodeMsgSub.getNodeName().equalsIgnoreCase("AUTORENEWAL_SUCCESS_MESSAGE")) {
                        userNodeMsgSub.setTextContent(autoRenewalMsg);
                    } else if (userNodeMsgSub.getNodeName().equalsIgnoreCase("ACT_DIFFERENTIAL_MESSAGE")) {
                        userNodeMsgSub.setTextContent(autoDiffMsg);
                    } else if (userNodeMsgSub.getNodeName().equalsIgnoreCase("ALERT_MESSAGE")) {
                        userNodeMsgSub.setTextContent(malrtMsg);
                    } else if (userNodeMsgSub.getNodeName().equalsIgnoreCase("SUSPEND_MESSAGE")) {
                        userNodeMsgSub.setTextContent(suspendMsg);
                    } else if (userNodeMsgSub.getNodeName().equalsIgnoreCase("STILL_SUSPEND_MESSAGE")) {
                        userNodeMsgSub.setTextContent(stillSuspendMsg);
                    } else if (userNodeMsgSub.getNodeName().equalsIgnoreCase("RETRY_STOPPED_MESSAGE")) {
                        userNodeMsgSub.setTextContent(retryStopMsg);
                    } else if (userNodeMsgSub.getNodeName().equalsIgnoreCase("BLACK_LIST_MESSAGE")) {
                        userNodeMsgSub.setTextContent(blackListMsg);
                    }
                }
            }
            // TransformerFactory instance is used to create Transformer objects.
            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = factory.newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            // create string from xml tree
            StringWriter sw = new StringWriter();
            StreamResult result = new StreamResult(sw);
            DOMSource source = new DOMSource(doc);
            transformer.transform(source, result);
            String xmlString = sw.toString();
    
            //File file = new File("E:/xgprs/xmlgprs/login.xml");
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(file)));
            bw.write(xmlString);
            bw.flush();
            bw.close();
        }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default

    That's a lot of code and not much description of what the problem is...
    How do you know it's not getting validated?
    What does the system do that it shouldn't...what doesn't it do that it should?

  3. #3
    madhuks is offline Member
    Join Date
    Jul 2010
    Posts
    2
    Rep Power
    0

    Default

    k..im reducing my code...here is my code...

    Java Code:
    package proj;
    
    import java.io.*;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Properties;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.w3c.dom.*;
    import javax.xml.parsers.*;
    import javax.xml.transform.*;
    import javax.xml.transform.dom.*;
    import javax.xml.transform.stream.*;
    
    public class delete extends HttpServlet {
    
        public void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    
            response.setContentType("text/html");
            PrintWriter pw = response.getWriter();
            String s = null;
            String packName = request.getParameter("packName");
    
            try {
                DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
                DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
    
                // Creating the path for XML File using Properties
                ServletContext servletContextObj = request.getSession().getServletContext();
                String excelTemplatesPath = servletContextObj.getRealPath("/");
                String filePaths = excelTemplatesPath + File.separator
                        + "config.properties";
                Properties propObj = new Properties();
                propObj.load(new FileInputStream(filePaths));
                String gprsLoginPath = null;
                gprsLoginPath = propObj.getProperty("GPRS_LOGIN_PATH");
                if (gprsLoginPath == null || gprsLoginPath.trim().equals("")) {
                    gprsLoginPath = excelTemplatesPath;
                }
                gprsLoginPath += File.separator + "login.xml";
                java.io.File file = new java.io.File(gprsLoginPath);
                Document doc = null;
                if (file.exists()) {
                    try {
                        doc = docBuilder.parse(file);
                    } catch (Exception ex) {
                        doc = docBuilder.newDocument();
                        Element root = doc.createElement("PACKS");
                        doc.appendChild(root);
                    }
                } else {
                    doc = docBuilder.newDocument();
                    // Creating Root Tag
                    Element root = doc.createElement("PACKS");
                    doc.appendChild(root);
                }
    
                // creating a new instance of a DOM to build a DOM tree.
                // Document doc = docBuilder.newDocument();
                delNode(file, doc, "PACK_NAME");
                pw.println("<b>Xml File Deleted Successfully</b>");
            } catch (Exception e) {
                System.out.println(e);
                e.printStackTrace();
            }
        }
    
        public static void delNode(java.io.File file, Node parent, String filter)
                throws Exception {
    
            NodeList children = parent.getChildNodes();
    
            for (int i = 0; i < children.getLength(); i++) {
                Node child = children.item(i);
    
                if (child.getNodeType() == Node.ELEMENT_NODE) {
    
                    if (child.getNodeName().equals(filter)) {
                        parent.removeChild(child);
                    } else {
                        delNode(file, child, filter);
                    }
                }
            }
            // TransformerFactory instance is used to create Transformer objects.
            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = factory.newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            // create string from xml tree
            StringWriter sw = new StringWriter();
            StreamResult result = new StreamResult(sw);
            //Document doc = null;
            DOMSource source = new DOMSource(parent);
            transformer.transform(source, result);
            String xmlString = sw.toString();
    
            //File file = new File("E:/xgprs/xmlgprs/login.xml");
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(file)));
            bw.write(xmlString);
            bw.flush();
            bw.close();
    
        }
    }

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

Similar Threads

  1. Checking udppackets in xp
    By abdullahansari in forum New To Java
    Replies: 1
    Last Post: 05-25-2010, 03:48 AM
  2. Checking if a file name already has .txt in it
    By AJArmstron@aol.com in forum New To Java
    Replies: 2
    Last Post: 04-17-2010, 12:45 PM
  3. checking file extensions
    By gisler in forum New To Java
    Replies: 3
    Last Post: 12-05-2009, 01:25 PM
  4. checking if there are equal numbers
    By nalinda in forum New To Java
    Replies: 0
    Last Post: 11-18-2007, 02:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •