I am trying to retrieve text in using unmarshalling example of JAXB but unable to retrieve the within ... tag. This is my first question and hence quite unsure on indenting my code, but here it goes :
LangFlag.java
package IDJAXBParser;
import java.util.List;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
#XmlType( propOrder = { "name", "description", "match", "context" } )
#XmlRootElement( name = "langFlag" )
public class LangFlag
{
String name;
public String getName()
{
return name;
}
#XmlAttribute( name = "name" )
public void setName( String name )
{
this.name = name;
}
String description;
public String getDescription()
{
return description;
}
#XmlElement( name = "description" )
public void setDescription( String description )
{
this.description = description;
}
String context;
#XmlAnyElement(BioHandler.class)
public String getContext()
{
return context;
}
public void setContext( String context )
{
this.context = context;
}
List<String> match;
public List<String> getMatch()
{
return match;
}
#XmlElement( name = "match" )
public void setMatch( List<String> match )
{
this.match = match;
}
#Override
public String toString()
{
StringBuffer str = new StringBuffer( "Name: " + getName() + "\n" );
str.append("Description:" + getDescription() + "\n");
str.append("Context:" + getContext() + "\n");
str.append("Match:" + getMatch() + "\n");
str.append("\n");
return str.toString();
}
}
ListOfLangFlags.java
package IDJAXBParser;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement( name = "listOfLangFlags" )
public class ListOfLangFlags
{
List<LangFlag> listOfLangFlags;
public List<LangFlag> getLangFlags()
{
return listOfLangFlags;
}
/**
* element that is going to be marshaled in the xml
*/
#XmlElement( name = "langFlag" )
public void setLangFlags( List<LangFlag> listOfLangFlags )
{
this.listOfLangFlags = listOfLangFlags;
}
public void add( LangFlag langFlag )
{
if( this.listOfLangFlags == null )
{
this.listOfLangFlags = new ArrayList<LangFlag>();
}
this.listOfLangFlags.add( langFlag );
}
#Override
public String toString()
{
StringBuffer str = new StringBuffer();
for( LangFlag langFlag : this.listOfLangFlags )
{
str.append( langFlag.toString() );
}
return str.toString();
}
}
UnMarshalJAXVBComplete.java
package IDJAXBParser;
import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import IDJAXBParser.ListOfLangFlags;
public class UnMarshalJAXVBComplete
{
public static void main( String[] args )
{
try
{
File file = new File( "testv1.xml" );
JAXBContext jaxbContext = JAXBContext.newInstance( ListOfLangFlags.class );
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
ListOfLangFlags langFlags = (ListOfLangFlags)jaxbUnmarshaller.unmarshal( file );
System.out.println( langFlags );
}
catch( JAXBException e )
{
e.printStackTrace();
}
}
}
This is my XML document :
<listOfLangFlags>
<langFlag name="Lang Flag Name">
<description>Lang Flag Description</description>
<context begin="0" end="100">I am so <span class="locality">blue </span>
I'm greener than purple. </context>
<suggestions/>
<match>I am so</match>
<match>blue</match>
</langFlag>
</listOfLangFlags>
BioHandler.java
package IDJAXBParser;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.bind.ValidationEventHandler;
import javax.xml.bind.annotation.DomHandler;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class BioHandler implements DomHandler<String, StreamResult> {
private static final String BIO_START_TAG = "<context>";
private static final String BIO_END_TAG = "</context>";
private StringWriter xmlWriter = new StringWriter();
public StreamResult createUnmarshaller(ValidationEventHandler errorHandler) {
xmlWriter.getBuffer().setLength(0);
return new StreamResult(xmlWriter);
}
public String getElement(StreamResult rt) {
String xml = rt.getWriter().toString();
int beginIndex = xml.indexOf(BIO_START_TAG) + BIO_START_TAG.length();
int endIndex = xml.indexOf(BIO_END_TAG);
return xml.substring(beginIndex, endIndex);
}
public Source marshal(String n, ValidationEventHandler errorHandler) {
try {
String xml = BIO_START_TAG + n.trim() + BIO_END_TAG;
StringReader xmlReader = new StringReader(xml);
return new StreamSource(xmlReader);
} catch(Exception e) {
throw new RuntimeException(e);
}
}
}
Any help would be appreciated! Thanks in advance
Here is a DomHandler implementation which convert between DOM object and String.
import java.io.StringReader;
import javax.xml.bind.ValidationEventHandler;
import javax.xml.bind.annotation.DomHandler;
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class BioHandler implements DomHandler<String, DOMResult> {
private StringBuilder buffer = new StringBuilder();
public DOMResult createUnmarshaller(ValidationEventHandler errorHandler) {
return new DOMResult();
}
public String getElement(DOMResult rt) {
Node n = rt.getNode();
Element ele = null;
if (n instanceof Document) {
ele = ((Document)n).getDocumentElement();
} else if (n instanceof DocumentFragment) {
ele = (Element)n.getChildNodes().item(0);
}
//StringBuilder sb = new StringBuilder(); //only capture the text under current node.
if (ele != null && "context".equals(ele.getLocalName())) {
try {
NodeList nl = (NodeList)XPathFactory.newInstance().newXPath()
.compile("descendant::text()").evaluate(ele, XPathConstants.NODESET);
int length = nl.getLength();
for (int i = 0; i < length; i++) {
buffer.append(nl.item(i).getTextContent());
}
} catch (XPathExpressionException e) {
throw new RuntimeException(e);
}
}
//for problem tracing
//System.err.println("BioHandler.getElement(), ele="+ele.getLocalName() +", result=["+result+"]");
return buffer.toString();
}
public Source marshal(String n, ValidationEventHandler errorHandler) {
try {
String xml = "<context>" + n.trim() + "</context>";
StringReader xmlReader = new StringReader(xml);
return new StreamSource(xmlReader);
} catch(Exception e) {
throw new RuntimeException(e);
}
}
}
During my testing, the unknown <suggestions/> element is handled by the same object. So I declare buffer as class variable and output captured content every time.
Related
How could I get value based on a key from an XML content http enpoint, so it is something like
<authority.result result="found 7 matches" startToken="xxxxxxx">
<TestEntry keyId="0right0" test="test" valueId="rightValue123" version="1"/>
<TestEntry keyId="0wrong" test="test" valueId="0wrongValue" version="1"/>
<TestEntry keyId="0wrong0" test="test" valueId="wrong" version="1"/>
</authority.result>
I would like to get the valueId when keyId=="0right0" only, I previously wrote following but could not get value for a specific key.
URL url = new URL(endpoint);
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(url.openStream());
String latest;
while (reader.hasNext()) {
if (reader.next() == XMLStreamConstants.START_ELEMENT) {
if (reader.getLocalName().equals("valueId")) {
latest = reader.getElementText();
return latest;
}
}
}
You need to distinguish XML element from an attribute. To read attribute name and value you have to use getAttributeName and getAttributeValue methods respectively.
Below you find example code how to read attributes:
import javax.xml.namespace.QName;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
public class XmlStreamApp {
public static void main(String[] args) throws IOException, XMLStreamException {
...
XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(stream);
Optional<String> value = findValueForTestEntry(reader, "0right0");
System.out.println(value);
}
private static Optional<String> findValueForTestEntry(XMLStreamReader reader, String keyValue) throws XMLStreamException {
while (reader.hasNext()) {
if (reader.next() == XMLStreamConstants.START_ELEMENT) {
String localName = reader.getLocalName();
if ("TestEntry".equals(localName)) {
Optional<String> optionalValue = getValueForKey(reader, keyValue);
if (optionalValue.isPresent()) {
return optionalValue;
}
}
}
}
return Optional.empty();
}
private static Optional<String> getValueForKey(XMLStreamReader reader, String keyValue) {
String value = "";
boolean found = false;
for (int attr = reader.getAttributeCount() - 1; attr >= 0; attr--) {
QName attributeName = reader.getAttributeName(attr);
if (attributeName.getLocalPart().equals("keyId")) {
found = keyValue.equals(reader.getAttributeValue(attr));
}
if (attributeName.getLocalPart().equals("valueId")) {
value = reader.getAttributeValue(attr);
}
}
return found ? Optional.of(value) : Optional.empty();
}
}
Above code prints:
Optional[rightValue123]
You could use an xpath to get to the desired value :
string(//TestEntry[#keyId="0right0"]/#valueId)
I have a xml file which has got some Japanese characters inside it. but when i am reading the files it is getting converted to some other characters.Please see the code below :-
Customer.java
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement
public class Customer {
#Override
public String toString() {
return "Customer [name=" + name + ", age=" + age + ", id=" + id + "]";
}
String name;
int age;
int id;
public String getName() {
return name;
}
#XmlElement
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
#XmlElement
public void setAge(int age) {
this.age = age;
}
public int getId() {
return id;
}
#XmlAttribute
public void setId(int id) {
this.id = id;
}
}
Conversion.java
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.Paths;
public class Conversion {
public static void main(String[] args)
throws Exception {
Conversion conversion=new Conversion();
Path path = Paths.get("C:\\file.xml");
conversion.doReadFileNew(path);
}
private static void doReadFileNew(Path fileLocation) throws IOException, FileNotFoundException {
final int READ_FILE_BUFFER_SIZE = Integer
.valueOf(System.getProperty("READ_FILE_BUFFER_SIZE", "8192"));
StringBuilder output = null;
try (RandomAccessFile raf = new RandomAccessFile(fileLocation.toFile(), "r");
FileChannel fc = raf.getChannel();) {
output = new StringBuilder(READ_FILE_BUFFER_SIZE);
try {
ByteBuffer buffer = ByteBuffer.allocate(READ_FILE_BUFFER_SIZE);
while (fc.read(buffer) > 0) {
buffer.flip();
for (int i = 0; i < buffer.limit(); i++) {
output.append((char)buffer.get());
}
buffer.clear();
}
} finally { }
} catch (Exception e) {
throw e;
}
System.out.println(output);
}
}
The Input file "file.xml" is :-
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customer id="100">
<age>29</age>
<name>株式会社三菱東京UFJ銀行</name>
</customer>
The OutPut is :-
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customer id="100">
<age>29</age>
<name>₩ᅠᆰ¥ᄐマ¦ᄐレᄂᄒ¦ᄌノ│マᄆ₩ンᄆ¦ᄎᆲUFJ←ハタ│ᄀフ</name>
</customer>
Please help .
You may have to add Charset.forName("UTF-8").decode(buffer):
private static void doReadFileNew(Path fileLocation) throws IOException, FileNotFoundException {
final int READ_FILE_BUFFER_SIZE = Integer
.valueOf(System.getProperty("READ_FILE_BUFFER_SIZE", "8192"));
StringBuilder output = null;
Charset charset = Charset.forName("UTF-8");
try (RandomAccessFile raf = new RandomAccessFile(fileLocation.toFile(), "r");
FileChannel fc = raf.getChannel();) {
output = new StringBuilder(READ_FILE_BUFFER_SIZE);
try {
ByteBuffer buffer = ByteBuffer.allocate(READ_FILE_BUFFER_SIZE);
while (fc.read(buffer) > 0) {
buffer.flip();
for (int i = 0; i < buffer.limit(); i++) {
output.append(charset.decode(buffer));
}
buffer.clear();
}
} finally { }
} catch (Exception e) {
throw e;
}
System.out.println(output);
}
Try this.
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class Conversion {
public static void main(String[] args) throws Exception {
doReadFileNew("C:\\file.xml");
}
private static void doReadFileNew(String path) throws FileNotFoundException, IOException {
BufferedReader in = new BufferedReader(new FileReader(path));
String line;
while((line = in.readLine()) != null)
{
System.out.println(line);
}
in.close();
}
}
jar from a apache server with php.
I use shell_exec and a give her my jar file.
But because i parse an xml file on my java class i have problem. Jar can't access xml.
Files
SampleSax.java
package phpJavaPack;
import java.io.IOException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class SampleSAX {
public static void main(String[] args) throws IOException, SAXException, ParserConfigurationException {
/*int i=0;
MyBufferedReaderWriter f = new MyBufferedReaderWriter();
f.openRFile("dblp.xml");
String sLine="";
while ((i<10) && (sLine=f.readLine()) != null) {
System.out.println(sLine);
i++;
}*/
int i=0;
while(i<args.length){
System.out.println("Argument's: " + args[0]);
System.setProperty("entityExpansionLimit", "1000000");
SAXParserFactory spfac = SAXParserFactory.newInstance();
spfac.setNamespaceAware(true);
SAXParser saxparser = spfac.newSAXParser();
MyHandler handler = new MyHandler(args[i]);
InputSource is = new InputSource("dblpmini.xml");
is.setEncoding("ISO-8859-1");
System.out.println("Please wait...");
saxparser.parse(is, handler);
System.out.println("---->" + handler.getprofessorsPublications());
i++;
}
//System.out.println("#####################################################################################################");
//System.out.println("List of George A. Vouros: " + handler.getprofessorsPublicationsValue("George A. Vouros"));
//System.out.println(handler.getProfessors());
//handler.createHtmlPage();//emfanizei mia html selida me ta apotelesmata
}
}
MyHandler.java
package phpJavaPack;
import java.util.ArrayList;
import java.util.Hashtable;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class MyHandler extends DefaultHandler {
private Publication publication;
protected Hashtable<String, ArrayList<Publication>> professorsPublications = new Hashtable<String, ArrayList<Publication>>();
private String temp ;
private ArrayList<Publication> al;
//private EntryLd entry = new EntryLd();
// public MyHandler() {
// super();
//
// String[] namesTable = entry.getNamesInput();
//
//
// for (String name: namesTable) {
//
// al = new ArrayList<Publication>();
// professorsPublications.put(name, al);
// }
//
// System.out.println("HashTable: " + professorsPublications);
// }
public MyHandler(String authorForSearch){
super();
String name = authorForSearch;
al = new ArrayList<Publication>();
professorsPublications.put(name, al);
System.out.println("HashTable: " + professorsPublications);
}
public Hashtable<String, ArrayList<Publication>> getprofessorsPublications() {
return professorsPublications;
}
public ArrayList<Publication> getprofessorsPublicationsValue(String author) {
return professorsPublications.get(author);
}
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
{
temp = "";
if (qName.equalsIgnoreCase("article") || qName.equalsIgnoreCase("inproceedings")
|| qName.equalsIgnoreCase("proceedings") || qName.equalsIgnoreCase("book")
|| qName.equalsIgnoreCase("incollection") || qName.equalsIgnoreCase("phdthesis")
|| qName.equalsIgnoreCase("mastersthesis") || qName.equalsIgnoreCase("www")) {
publication = new Publication();
}
}
public void characters(char[] ch, int start, int length) {
temp = new String(ch, start, length);
System.out.println("----->>>" + temp);
//System.out.print(" <--- My temp's start: " + temp + " :My temp's end --> ");
}
public void endElement(String uri, String localName, String qName) throws SAXException
{
if (qName.equalsIgnoreCase("article") || qName.equalsIgnoreCase("inproceedings")
|| qName.equalsIgnoreCase("proceedings") || qName.equalsIgnoreCase("book")
|| qName.equalsIgnoreCase("incollection") || qName.equalsIgnoreCase("phdthesis")
|| qName.equalsIgnoreCase("mastersthesis") || qName.equalsIgnoreCase("www"))
{
for(int i=0; i<publication.getAuthors().size(); i++) {
String authorName = publication.getAuthors().get(i);
if(this.professorsPublications.containsKey(authorName)) {
this.publication.setType(localName);
this.professorsPublications.get(authorName).add(publication);
}
}
}
if(qName.equalsIgnoreCase("author")) {
publication.addAuthor(temp);
}
else if(qName.equalsIgnoreCase("title")) {
publication.setTitle(temp);
}
else if(qName.equalsIgnoreCase("year")) {
publication.setYear(Short.parseShort(temp));
}
else if(qName.equalsIgnoreCase("booktitle")) {
publication.setBooktitle(temp);
}
//String xl = publication.toString();
//System.out.println(xl);
}
}
How can give right the xml on a runnable jar?
Thnx
see PHP exec() command: how to specify working directory? - most probably the proc_open suggestion/example there is the best one
see the other suggestions at that thread too, like chdir
I am new born for Jaxb and trying to do read/write operation in xml.
I am done with the write operation but having trouble with the read one.
I have the following xml-
<docOperations>
<SkuSlabs id="1">
<docId>677-WORK</docId>
<itemIds>11</itemIds>
<itemName>new item addedaaaaaa</itemName>
</SkuSlabs>
<SkuSlabs id="2">
<docId>699-WORK</docId>
<itemIds>21</itemIds>
<itemName>extra</itemName>
</SkuSlabs>
</docOperations>
Now i want to unmarshal the SkuSlabs object based on the condition supplied 'where id = 1', but don't know how to achieve that.
Please help.
Here you are (as you want add same access modifiers to attributes):
package pl.skuslab;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(name = "SkuSlabs")
#XmlAccessorType(XmlAccessType.FIELD)
public class SkusLab {
#XmlAttribute
int id;
String docId;
int itemIds;
String itemName;
public SkusLab(int id, String docId, int itemIds, String itemName) {
super();
this.id = id;
this.docId = docId;
this.itemIds = itemIds;
this.itemName = itemName;
}
public SkusLab() {
super();
}
#Override
public String toString() {
return "SkusLab [id=" + id + ", docId=" + docId + ", itemIds=" + itemIds + ", itemName=" + itemName + "]";
}
}
Class DocOperation:
package pl.skuslab;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement
#XmlAccessorType(XmlAccessType.FIELD)
public class DocOperation {
#XmlElement(name = "SkuSlabs")
List<SkusLab> docOperations = new ArrayList<SkusLab>();
}
Class with the main function. Firstly I generate XML like you wrote in question, then I unmarshall xml to obejcts. First obejct is printed.
package pl.skuslab;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
public class SkusLabJaxb {
private static JAXBContext jc;
static {
try {
jc = JAXBContext.newInstance(DocOperation.class);
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
private static Marshaller getMarshaller() {
try {
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
return marshaller;
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
private static Unmarshaller getUnmarshaller() {
try {
Unmarshaller unmarshaller = jc.createUnmarshaller();
return unmarshaller;
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) {
String xml = "";
try {
DocOperation doper = new DocOperation();
doper.docOperations.add(new SkusLab(1, "677-WORK", 11, "new item addedaaaaaa"));
doper.docOperations.add(new SkusLab(2, "699-WORK", 21, "extra"));
StringWriter sw = new StringWriter();
getMarshaller().marshal(doper, sw);
xml = sw.toString();
System.out.println(xml);
} catch (JAXBException e) {
e.printStackTrace();
}
try {
DocOperation docOperation = (DocOperation) getUnmarshaller().unmarshal(
new StringReader(xml));
System.out.println(docOperation.docOperations.get(0).toString());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
this is my nodefinder.java file
package com.acme.web.action.executer;
import java.sql.ResultSet;
import java.util.Map;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.component.UIActionLink;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.cmr.search.SearchService;
public class NodeFinder {
// private static final String = null;
SearchParameters sp = new SearchParameters();
private NodeService nodeService;
private FileFolderService fileFolderService;
//geting the filefolder service
public FileFolderService getFileFolderService() {
return fileFolderService;
}
// setting the file folder service
public void setFileFolderService(FileFolderService fileFolderService) {
this.fileFolderService = fileFolderService;
}
// getting the node servise
public NodeService getNodeService() {
return nodeService;
}
// setting the node server
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
public void execute(ActionEvent event) {
ResultSet resultSet_s = null;
UIActionLink comp = (UIActionLink) event.getComponent();
Map<String, String> params = comp.getParameterMap();
String id = params.get("id1");
System.out.println("1");
NodeRef actionedUponNodeRef = new NodeRef(Repository.getStoreRef(), id);
String qry_s = "#cm\\:name:train";
System.out.println("2");
SearchParameters sp_s = new SearchParameters();
System.out.println("3");
sp_s.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
sp_s.setLanguage(SearchService.LANGUAGE_LUCENE);
sp_s.setQuery(qry_s);
System.out.println( "4" );
Node node = new Node(actionedUponNodeRef);
System.out.println("5");
resultSet_s = (ResultSet) Repository.getServiceRegistry(
FacesContext.getCurrentInstance()).getSearchService().query(
sp_s);
System.out.println("5.1");
if (resultSet_s != null) {
System.out.println("6");
System.out.println("Node value is::::" + node.getName());
}
}
}
Because you imported java.sql.ResultSet instead of an alfresco class/interface compatible to org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet
Look at that line ...(ResultSet) Repository.getServiceRegistry(..., then look at your exception and finally at your imports. There you will see that ResultSet is actually java.sql.ResultSet (which is indicated by your ClassCastException's message).
If you then look at the super classes or interfaces of org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet I'd say you won't find any java.sql.ResultSet. That's why you get that exception.