Subversion Repositories SmartDukaan

Rev

Rev 6040 | Rev 6602 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6040 Rev 6257
Line 34... Line 34...
34
 
34
 
35
import org.apache.commons.lang.StringEscapeUtils;
35
import org.apache.commons.lang.StringEscapeUtils;
36
import org.apache.commons.lang.StringUtils;
36
import org.apache.commons.lang.StringUtils;
37
import org.json.JSONObject;
37
import org.json.JSONObject;
38
 
38
 
-
 
39
import org.w3c.dom.*;
-
 
40
import org.apache.xerces.parsers.DOMParser;
-
 
41
 
-
 
42
import javax.xml.transform.*;
-
 
43
import javax.xml.transform.dom.DOMSource;
-
 
44
import javax.xml.transform.stream.StreamResult;
-
 
45
 
39
/**
46
/**
40
 * Command line utility to generate xml file for partners
47
 * Command line utility to generate xml file for partners
41
 * 
48
 * 
42
 * @author rajveer
49
 * @author rajveer
43
 *
50
 *
Line 795... Line 802...
795
    	productXMLSnippets.add("</root>");
802
    	productXMLSnippets.add("</root>");
796
    	String productDataXML = StringUtils.join(productXMLSnippets, "\n");
803
    	String productDataXML = StringUtils.join(productXMLSnippets, "\n");
797
    	DBUtils.store(productDataXML, thinkDigitFeedFileName);
804
    	DBUtils.store(productDataXML, thinkDigitFeedFileName);
798
 
805
 
799
    }
806
    }
-
 
807
    
-
 
808
    public static void updatePriceForEntity(long catalogItemId, double sp, double mrp){
-
 
809
    	try{
-
 
810
    		String filename = Utils.EXPORT_PARTNERS_CONTENT_PATH + "saholicmobilephones.xml";
-
 
811
    		File file = new File(filename);
-
 
812
    		if (file.exists()){
-
 
813
    			DOMParser parser = new DOMParser();
-
 
814
    			parser.parse(filename);
-
 
815
    			Document doc = parser.getDocument();
-
 
816
    			NodeList list = doc.getElementsByTagName("ProductSKU");
-
 
817
    			for(int i=0; i<list.getLength(); i++){
-
 
818
    				if(list.item(i).getTextContent().equals(catalogItemId+"")){
-
 
819
    					Node spNode = doc.getElementsByTagName("ProductPrice").item(i);
-
 
820
    					spNode.setTextContent(sp+"");
-
 
821
    					Node mrpNode = doc.getElementsByTagName("ProductMRP").item(i);
-
 
822
    					mrpNode.setTextContent(mrp+"");
-
 
823
    				}
-
 
824
    			}
-
 
825
    			writeXmlFile(doc, filename);
-
 
826
    		}
-
 
827
    		else{
-
 
828
    			System.out.println("File not found!");
-
 
829
    		}
-
 
830
    	}
-
 
831
    	catch (Exception e){
-
 
832
    		e.getMessage();
-
 
833
    	}
-
 
834
    }
-
 
835
    
-
 
836
    // This method writes a DOM document to a file
-
 
837
    public static void writeXmlFile(Document doc, String filename) {
-
 
838
    	try {
-
 
839
    		// Prepare the DOM document for writing
-
 
840
    		Source source = new DOMSource(doc);
-
 
841
 
-
 
842
    		// Prepare the output file
-
 
843
    		File file = new File(filename);
-
 
844
    		Result result = new StreamResult(file);
-
 
845
 
-
 
846
    		// Write the DOM document to the file
-
 
847
    		Transformer xformer = TransformerFactory.newInstance().newTransformer();
-
 
848
    		xformer.transform(source, result);
-
 
849
    	} catch (TransformerConfigurationException e) {
-
 
850
    	} catch (TransformerException e) {
-
 
851
    	}
-
 
852
    }
800
}
853
}
801
854