Post by zastil » Thu Feb 04, 2016 4:48 am

I have written a vqMod xml to ocMod converter in JAVA

If you want any vqMod converted I can do them for you for a $5 for £3 payment emailed back to you just send paypal gift to info@worldprops.com and the file to zastil@gmail.com.

(it maybe need some changes for attributes I have missed)

Code: Select all

package vqMod2ocMod;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;

import java.io.File;

public class ReadXMLFile {

  public static void main(String argv[]) {

    try {
    ocmod objOcMod = new ocmod();
	File fXmlFile = new File("OldFile.xml");
	DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
	DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
	Document doc = dBuilder.parse(fXmlFile);
			
	//optional, but recommended
	//read this - http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
	doc.getDocumentElement().normalize();

	System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
			
	NodeList nList = doc.getElementsByTagName("modification");
			
	System.out.println("----------------------------");

	for (int temp = 0; temp < nList.getLength(); temp++) {

		Node nNode = nList.item(temp);
				
		//System.out.println("\nCurrent Element :" + nNode.getNodeName());
				
		if (nNode.getNodeType() == Node.ELEMENT_NODE) {

			Element eElement = (Element) nNode;
			objOcMod.setCode(eElement.getElementsByTagName("id").item(0).getTextContent().toString().toLowerCase().replace(" ", ""));
			objOcMod.setAuthor(eElement.getElementsByTagName("author").item(0).getTextContent());
			objOcMod.setName(eElement.getElementsByTagName("id").item(0).getTextContent());
			objOcMod.setVersion(eElement.getElementsByTagName("version").item(0).getTextContent());
			objOcMod.setLink("http://www.zastil.co.uk");
			
			
		}
	}
	// Now loop the file mods
	Element eFiles = (Element) nList.item(0);
	NodeList nListFiles = eFiles.getElementsByTagName("file");
	
	

	// Loop the element files in XML
	for (int temp1 = 0; temp1 < nListFiles.getLength(); temp1++) {
	
		ocmodFile objOcModFile = new ocmodFile();
		// Now grab oparations inside the file
		Element eOperations = (Element) nListFiles.item(temp1);
		NodeList nOperations = eOperations.getElementsByTagName("operation");
			
			
		// Loop for all elements for operations	
		for (int temp2 = 0; temp2 < nOperations.getLength(); temp2++) {
			// Get the node for current option
			Node nOperation = nOperations.item(temp2);
			// Also need it as Element for as find children serach and add
			Element eOperation = (Element) nOperation;
			// Set a new obj for Operation
			ocmodOperation objOcmodOperation = new ocmodOperation();
			
			// Find operation attributes
			// here we also need the atrribute from search i.e replace and index
			for (int temp4 = 0; temp4 < eOperation.getAttributes().getLength(); temp4++){
				if (eOperation.getAttributes().item(temp4).getNodeName() == "error") objOcmodOperation.setError(eOperation.getAttributes().item(temp4).getTextContent());
			}
		
			// Grab the 2 nodes search and add
			Node nSearch = eOperation.getElementsByTagName("search").item(0);
			Node nAdd    = eOperation.getElementsByTagName("add").item(0);
			
			// here we also need the atrribute from search i.e replace and index
			for (int temp3 = 0; temp3 < nSearch.getAttributes().getLength(); temp3++){
				if (nSearch.getAttributes().item(temp3).getNodeName() == "position") objOcmodOperation.setPosition(nSearch.getAttributes().item(temp3).getTextContent());
				if (nSearch.getAttributes().item(temp3).getNodeName() == "index") objOcmodOperation.setIndex(nSearch.getAttributes().item(temp3).getTextContent());
			}

			
			// Trim the search and add and set them to current operation object
			objOcmodOperation.setSearch(nSearch.getTextContent().trim());
			objOcmodOperation.setAdd(nAdd.getTextContent().trim());
			
			
			
			// Now add the operation obj to the file obj
			objOcModFile.setOperation(objOcmodOperation);
			// Get the name value in vqMod and turn into Path only need to take item 0 as only 1 attribute in name field
			objOcModFile.setPath(nListFiles.item(temp1).getAttributes().item(0).getTextContent());
			
		}
		objOcMod.setFile(objOcModFile);

	}
	
	
	WriteXMLFile writeXMLFile = new WriteXMLFile();
	writeXMLFile.writeXML(objOcMod);
	
    } catch (Exception e) {
	e.printStackTrace();
    }
  }

}

Code: Select all

package vqMod2ocMod;
import java.io.File;
import java.io.StringReader;
import java.io.StringWriter;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class WriteXMLFile {

	public static void main(String argv[]) {
	}
	
	public void writeXML(ocmod objOcMod) {
	  try {

		DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

		// root elements
		Document doc = docBuilder.newDocument();
		// Remove Standalon
		doc.setXmlStandalone(true);
		
		Element rootElement = doc.createElement("modification");
		doc.appendChild(rootElement);

		// code element
		Element code = doc.createElement("code");
		rootElement.appendChild(code);
		code.appendChild(doc.createTextNode(objOcMod.getCode()));
		
		// name element
		Element name = doc.createElement("name");
		rootElement.appendChild(name);
		name.appendChild(doc.createTextNode(objOcMod.getName()));
		
		// version element
		Element version = doc.createElement("version");
		rootElement.appendChild(version);
		version.appendChild(doc.createTextNode(objOcMod.getVersion()));
		
		// author element
		Element author = doc.createElement("author");
		rootElement.appendChild(author);
		author.appendChild(doc.createTextNode(objOcMod.getAuthor()));
		
		// link element
		Element link = doc.createElement("link");
		rootElement.appendChild(link);
		link.appendChild(doc.createTextNode(objOcMod.getLink()));
		
		for (ocmodFile lstFile : objOcMod.getFiles()){
			
			// file element
			Element file = doc.createElement("file");
			file.setAttribute("path", lstFile.getPath());
			rootElement.appendChild(file);
			for (ocmodOperation lstOperation: lstFile.getOperations()){
				// operation element
				Element operation = doc.createElement("operation");
				// Add error attribute if exists
				if (lstOperation.getError().length() > 0) operation.setAttribute("error", lstOperation.getError().toString());
				file.appendChild(operation);
				
				Element search = doc.createElement("search");
				operation.appendChild(search);
				search.appendChild(doc.createCDATASection(lstOperation.getSearch()));
				
				Element add = doc.createElement("add");
				operation.appendChild(add);
				add.appendChild(doc.createCDATASection(lstOperation.getAdd()));
				
				String strReplace = lstOperation.getPosition().toString();
				if (strReplace.length() > 0) add.setAttribute("replace", strReplace);
				
				if (lstOperation.getIndex().length() > 0) search.setAttribute("index", lstOperation.getIndex().toString());
			}
			
		}

	

		// write the content into xml file

        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        transformerFactory.setAttribute("indent-number", 2);
        Transformer transformer = transformerFactory.newTransformer(); 
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
		DOMSource source = new DOMSource(doc);
		StreamResult result = new StreamResult(new File("NewFile.xml"));

		// Output to console for testing
		//StreamResult result = new StreamResult(System.out);

		transformer.transform(source, result);

		System.out.println("File saved!");

	  } catch (ParserConfigurationException pce) {
		pce.printStackTrace();
	  } catch (TransformerException tfe) {
		tfe.printStackTrace();
	  }
	}
	

}

Code: Select all

package vqMod2ocMod;

import java.util.ArrayList;
import java.util.List;

public class ocmod {
	private String code;
	private String name;
	private String version;
	private String author;
	private String link;
	private List<ocmodFile> files = new ArrayList<ocmodFile>();
	/**
	 * @return the code
	 */
	public String getCode() {
		return code;
	}
	/**
	 * @param code the code to set
	 */
	public void setCode(String code) {
		this.code = code;
	}
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return the version
	 */
	public String getVersion() {
		return version;
	}
	/**
	 * @param version the version to set
	 */
	public void setVersion(String version) {
		this.version = version;
	}
	/**
	 * @return the author
	 */
	public String getAuthor() {
		return author;
	}
	/**
	 * @param author the author to set
	 */
	public void setAuthor(String author) {
		this.author = author;
	}
	/**
	 * @return the link
	 */
	public String getLink() {
		return link;
	}
	/**
	 * @param link the link to set
	 */
	public void setLink(String link) {
		this.link = link;
	}
	public List<ocmodFile> getFiles() {
		return files;
	}
	public void setFiles(List<ocmodFile> files) {
		this.files = files;
	}
	
	public void setFile(ocmodFile file) {
		this.files.add(file);
	}
	
	public ocmodFile getOperation(int index) {
		return this.files.get(index);
	}

}

Code: Select all

package vqMod2ocMod;

import java.util.ArrayList;
import java.util.List;

public class ocmodFile {
	private String path;
	private List<ocmodOperation> operations = new ArrayList<ocmodOperation>();

	public List<ocmodOperation> getOperations() {
		return operations;
	}

	public void setOperations(List<ocmodOperation> operations) {
		this.operations = operations;
	}
	
	public void setOperation(ocmodOperation operation) {
		this.operations.add(operation);
	}
	
	public ocmodOperation getOperation(int index) {
		return this.operations.get(index);
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}
}

Code: Select all

package vqMod2ocMod;

public class ocmodOperation {
	private String search;
	private String add;
	private String position = "";
	private String index = "";
	private String error = "";
	
	public String getAdd() {
		return add;
	}
	public void setAdd(String add) {
		this.add = add;
	}
	public String getSearch() {
		return search;
	}
	public void setSearch(String search) {
		this.search = search;
	}
	public String getPosition() {
		return position;
	}
	public void setPosition(String position) {
		this.position = position;
	}
	public String getIndex() {
		return index;
	}
	public void setIndex(String index) {
		this.index = index;
	}
	public String getError() {
		return error;
	}
	public void setError(String error) {
		this.error = error;
	}
}

Newbie

Posts

Joined
Thu Jun 25, 2015 6:56 pm

Post by Qphoria » Thu Feb 04, 2016 11:34 pm

LOL this is so unnecessary.

By the way the next version of vQmod supports ocmod format as well so you can simply upload the ocmod xml file to the vqmod/xml folder and not have to bother with the annoying modifications page in the admin.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by zastil » Sun Feb 07, 2016 2:54 am

I disagree keeping all modules in Extension Installer rather than using ftp to upload xml sucks big time. It enable easier editing and all files in one place.

Also can't wait for update as who know when we get it. This is workaround and code did not take long to write it.

Newbie

Posts

Joined
Thu Jun 25, 2015 6:56 pm

Post by IP_CAM » Sun Feb 07, 2016 12:55 pm

Bloody NonPro Question, will this only function, if a User has JAVA installed on it's Machine ?

But since I never was familiar with, and/or cared about Java, I really don't know,
and would never install anything to it, anywhere, in any way, since it's well known to
be a Mayor Source of Security Concerns...
Ernie

My Github OC Site: https://github.com/IP-CAM
5'600 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by Qphoria » Mon Feb 08, 2016 12:19 pm

zastil wrote:I disagree keeping all modules in Extension Installer rather than using ftp to upload xml sucks big time. It enable easier editing and all files in one place.

Also can't wait for update as who know when we get it. This is workaround and code did not take long to write it.
Then use vQmod manager. file based mod is much simpler because you don't have to worry about being locked out of admin. One bad ocmod can break your admin and you'll need to know how to use phpmyadmin to delete the code. Also if you want to adjust the ocmod, you can't without editing it in phpmyadmin or having the original file and uninstalling, editing, reuploading, refreshing.. then going in and disabling maintenance mod everytime.

A bad vqmod file can simply be deleted and edited easily in-place. You see any edits immediately without having to reupload, refresh, etc.

ocmod will never be better than vQmod

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by OSWorX » Mon Feb 08, 2016 5:55 pm

Qphoria wrote:One bad ocmod can break your admin and you'll need to know how to use phpmyadmin to delete the code.
Not really true.
Simply go to the store using your preferred FTP-Client and delete all files inside ../system/modification ( <OC 2.1) or ../system/storage/modification (OC >= 2.1.x)

Then you should be able to use your backend as usual, go to Modifications and disable all extensions and refresh.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria
Who is online

Users browsing this forum: No registered users and 3 guests