Thursday, November 29, 2012
Plist File Parsing Using Java
Plist File Parsing Using Java
Below example illustrates , how to iterate over a plist file Nodes using apache's XMLPropertyListConfiguration
public void infoPlistConversion(String plistPath) throws Exception {
XMLPropertyListConfiguration conf = new XMLPropertyListConfiguration(plistPath);
System.out.println("root node children size => "+ conf.getRootNode().getChildrenCount());
System.out.println("conf root => " + conf.getRootNode().getChild(0).getName());
System.out.println("conf.getRoot().getChild(0).getValue() => " + conf.getRootNode().getChild(0).getValue());
List children = conf.getRoot().getChildren();
printChildrenValue(children);
}
private void printChildrenValue(List children) {
if (children instanceof List) {
List<PListNode> configs = (List<PListNode>) children;
for (PListNode pListNode : configs) {
// sub nodes
if (pListNode.getValue() == null && pListNode.getChildrenCount() > 1) {
List pListNodeChildren = pListNode.getChildren();
System.out.println("-------------------------------------------------");
System.out.println("plist Name root => "+ pListNode.getName());
printChildrenValue(pListNodeChildren);
// just print values
} else {
// if it is ConfigParam and elements are not null
System.out.println("plist Name => "+ pListNode.getName());
System.out.println("plist Value => "+ pListNode.getValue());
}
}
}
}
--
Thank you.
Regards,
Kaleeswaran.S
Below example illustrates , how to iterate over a plist file Nodes using apache's XMLPropertyListConfiguration
public void infoPlistConversion(String plistPath) throws Exception {
XMLPropertyListConfiguration conf = new XMLPropertyListConfiguration(plistPath);
System.out.println("root node children size => "+ conf.getRootNode().getChildrenCount());
System.out.println("conf root => " + conf.getRootNode().getChild(0).getName());
System.out.println("conf.getRoot().getChild(0).getValue() => " + conf.getRootNode().getChild(0).getValue());
List children = conf.getRoot().getChildren();
printChildrenValue(children);
}
private void printChildrenValue(List children) {
if (children instanceof List) {
List<PListNode> configs = (List<PListNode>) children;
for (PListNode pListNode : configs) {
// sub nodes
if (pListNode.getValue() == null && pListNode.getChildrenCount() > 1) {
List pListNodeChildren = pListNode.getChildren();
System.out.println("-------------------------------------------------");
System.out.println("plist Name root => "+ pListNode.getName());
printChildrenValue(pListNodeChildren);
// just print values
} else {
// if it is ConfigParam and elements are not null
System.out.println("plist Name => "+ pListNode.getName());
System.out.println("plist Value => "+ pListNode.getValue());
}
}
}
}
--
Thank you.
Regards,
Kaleeswaran.S
Monday, October 29, 2012
Tomcat Maven Plugin Remote Debugging using Eclipse
I am developing a maven based web application. i am running the application with tomcat maven plugin like
mvn tomcat:run
I want to debug the application from eclipse.
Thank you.
Regards,
Kaleeswaran.S
mvn tomcat:run
I want to debug the application from eclipse.
Step 1:
export MAVEN_OPTS="-Xmx512M -XX:MaxPermSize=512m" which allocates 512 MB of memory.
Step 2:
export MAVEN_OPTS="-agentlib:jdwp=transport=dt_socket,address=2480,server=y,suspend=n"
Step 3:
run the application like mvn tomcat:run
step 4:
connect to port 2480 in eclipse remote debugging.
Enjoy. Happy Debugging.
-- Thank you.
Regards,
Kaleeswaran.S
Thursday, August 16, 2012
Jdom CRUD Operations
Hi,
Jdom CRUD Operations
Here is sample code to do some operations like
//Adding elements
public void addElementAtXpath() {
try {
XPath xpath = XPath.newInstance("publishers");
xpath.addNamespace(root_.getNamespace());
Element publisherNode = (Element) xpath.selectSingleNode(root_);
org.jdom.Element element = new Element("kalees");
element.addContent(createElement(CI_FILE_RELEASE_OVERRIDE_AUTH_NODE, TRUE));
publisherNode.addContent(element);
} catch (Exception e) {
e.printStackTrace();
}
}
// Changing attributes
public void changeAttributeValue() {
try {
XPath xpath = XPath.newInstance("scm");
xpath.addNamespace(root_.getNamespace());
Element scmNode = (Element) xpath.selectSingleNode(root_);
scmNode.setAttribute("class", "Kalees");
} catch (Exception e) {
e.printStackTrace();
}
}
//Deleting Elements
public void deleteElementAtXpath() {
//deleting a node...
// deleting content of a node
//triggerNode.removeContent();
try {
String childName = "hudson.plugins.emailext.ExtendedEmailPublisher";
XPath xpath = XPath.newInstance("publishers");
xpath.addNamespace(root_.getNamespace());
Element triggerNode = (Element) xpath.selectSingleNode(root_); // if it is null then element is not present
triggerNode.removeChild(childName);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Element createElement(String nodeName, String NodeValue) {
org.jdom.Element element = new Element(nodeName);
if (NodeValue != null) {
element.addContent(NodeValue);
}
return element;
}
--
Thank you.
Regards,
Kaleeswaran.S
Jdom CRUD Operations
Here is sample code to do some operations like
//Adding elements
public void addElementAtXpath() {
try {
XPath xpath = XPath.newInstance("publishers");
xpath.addNamespace(root_.getNamespace());
Element publisherNode = (Element) xpath.selectSingleNode(root_);
org.jdom.Element element = new Element("kalees");
element.addContent(createElement(CI_FILE_RELEASE_OVERRIDE_AUTH_NODE, TRUE));
publisherNode.addContent(element);
} catch (Exception e) {
e.printStackTrace();
}
}
// Changing attributes
public void changeAttributeValue() {
try {
XPath xpath = XPath.newInstance("scm");
xpath.addNamespace(root_.getNamespace());
Element scmNode = (Element) xpath.selectSingleNode(root_);
scmNode.setAttribute("class", "Kalees");
} catch (Exception e) {
e.printStackTrace();
}
}
//Deleting Elements
public void deleteElementAtXpath() {
//deleting a node...
// deleting content of a node
//triggerNode.removeContent();
try {
String childName = "hudson.plugins.emailext.ExtendedEmailPublisher";
XPath xpath = XPath.newInstance("publishers");
xpath.addNamespace(root_.getNamespace());
Element triggerNode = (Element) xpath.selectSingleNode(root_); // if it is null then element is not present
triggerNode.removeChild(childName);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Element createElement(String nodeName, String NodeValue) {
org.jdom.Element element = new Element(nodeName);
if (NodeValue != null) {
element.addContent(NodeValue);
}
return element;
}
--
Thank you.
Regards,
Kaleeswaran.S
Wednesday, August 8, 2012
Eclisep Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf
Eclisep Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf
If you face this issue in eclipse while running a standalone java application. Eclipse will allocate only 384 MB of Java heap memory. based on the type of JRE you are using and eclipse plugin and application size, this issue occurs. we have to increase heap memory size. To increase the available heap memory, right click your java progrram click "run as -> run configurations" . click argument tab and type -Xms1024M -Xmx1024M in VM arguments field. This increases VM size while running from eclipse.

--
Thank you.
Regards,
Kaleeswaran.S
If you face this issue in eclipse while running a standalone java application. Eclipse will allocate only 384 MB of Java heap memory. based on the type of JRE you are using and eclipse plugin and application size, this issue occurs. we have to increase heap memory size. To increase the available heap memory, right click your java progrram click "run as -> run configurations" . click argument tab and type -Xms1024M -Xmx1024M in VM arguments field. This increases VM size while running from eclipse.

--
Thank you.
Regards,
Kaleeswaran.S
Thursday, August 2, 2012
JDOM - How to insert an element, after another
JDOM - How to insert an element, after another
private Document document_ = null;
private Element root_ = null;
@Test
public void generateXml() {
//Url path of the file
String filePath = "http://172.................. .xml";
testXmlGeneration(filePath);
}
private void testXmlGeneration(String url) {
try {
SAXBuilder builder = new SAXBuilder();
// giving xml file url to jdom for parsing
document_ = builder.build(url);
root_ = document_.getRootElement();
// creating necessary elements which is to be appended at a particular point of the location in xml
org.jdom.Element element = new Element("release");
element.addContent(createElement("override", "true"));
element.addContent(createElement("url", "http://outside.out.coml"));
element.addContent(createElement("username", "kaleeswaran"));
element.addContent(createElement("password", "xm0QczqM6k9x10Os1z0k="));
element.addContent(createElement("rpackage", "PackageRed"));
element.addContent(createElement("release", "release"));
element.addContent(createElement("file__patterns", null).addContent(createElement("hudson.plugins.collabnet.documentuploader.FilePattern", "*.zip")));
// i want to add the generated elements after the publish tag in the xml
XPath xpath = XPath.newInstance("publish");
xpath.addNamespace(root_.getNamespace());
Element pullisherNode = (Element) xpath.selectSingleNode(root_);
// here specify the index value where the element should be added and pass the element
pullisherNode.getContent().add(3, element);
File dest = new File("/Users/kaleeswaran/Desktop/gonfig.xml");
InputStream configAsStream = getConfigAsStream();
ciManager.streamToFile(dest, configAsStream) ;
System.out.println("new value added =======> " + url);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Element createElement(String nodeName, String NodeValue) {
org.jdom.Element element = new Element(nodeName);
if (NodeValue != null) {
element.addContent(NodeValue);
}
return element;
}
public InputStream getConfigAsStream() throws IOException {
XMLOutputter xmlOutput = new XMLOutputter();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
xmlOutput.output(document_, outputStream);
return new ByteArrayInputStream(outputStream.toByteArray());
}
--
Thank you.
Regards,
Kaleeswaran.S
Subscribe to:
Posts (Atom)