Win a copy of Functional Design and Architecture this week in the Functional programming forum!

Siju Odeyemi

Greenhorn
+ Follow
since Jan 16, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Siju Odeyemi

prem & Wouter, thanks for responses.

I don't know regexp syntax at all, I know that the split method breaks the string up everytime it encounters the tag, but I need an expression that does what I explained in my opening post.

Cheers guys.

10 years ago

I've got a String variable expFile with the following value in it:



THEN I split the string using the following method:



I'm trying to write a regular expression to split the file after every 10 paragraphs OR at every 1000 characters at most. Unfortunately, I can't seem to get the regular expression right. Can someone with regex skills please show me the light? I'm quite desperate.

Thanks in advance.
10 years ago
Finally solved this problem. The method getFilesDir() in the ContextWrapper class in the Android API returns the app data directory without you having to hardcode it:



The code above effectively returns the right dir preventing any errors from surfacing as a result of different phones using different locations. Joy.
10 years ago

I'm using /data/data/{application_package}/files to store and load "user supplied" files needed in my application.

This works fine in my emulators but I just looked on my HTC phone and though it has the /data directory there is nothing inside it. I would have guessed that each application would have a private space in there automatically on installation as per "/data/data/{application_package}" but this is not the case.

PROBLEM: My application will obviously fail if I installed it on a real device (i.e. FileNotFoundException thrown due to directory literally not existing on the phone) EXCEPT I explicitly create the directory structure myself (in code) during the first run of the application. This seems like a bit of a hack to me. Has anyone else had to work with these directories? Any insights?

Thanks in advance.
10 years ago
Thanks Ulf, the CDATA section solves my problem.
10 years ago

Ulf Dittmer wrote:What do you mean by "html text"? The XML file doesn't seem to contain any HTML. If it in fact does (any you just didn't post the whole thing) then it would need to be kept in a CDATA section.

My first guess would be that some of the BasePresentationParser.XYZ strings are misspelt.

Does that handler work for that file in a Java SE environment? Would be easier to debug than as part of an Android app.

In the future, please UseCodeTags when posting code of any length. It's unnecessarily hard to read as it is, making it less likely that people will bother to do so.



Thanks for the response Ulf. Indeed I posted the wrong xml. The one I intended to post is slightly different and has some of the text wrapped in bold and italic (html) tags.

As you've stated, my problem was probably caused by not using CDATA section to store the html content. Could you please specify an example of how the CDATA section should look? In Adobe Flex I would do something like this but I'm not sure if it's Flex specific:




10 years ago
Hi people,

I'm writing an android app that loads xml files from the /data/data/{appname}/files directory, parses the files using SAX and puts the contents of the xml files into Java objects.

I've managed to read in the xml files successfully using this code:
FileInputStream fis = activity.openFileInput(fileName);

where "fileName" is the name of a file in the /data/data/{appname}/files directory.

I've also got the parsing working to some extent using Xml.parse(...)

THE PROBLEM is, when the tags are read in, some of them return with the expected content and some return with a "null" as if there is no content in there. I *suspect* the problem has to do with not escaping special characters such as full stops, tags, spaces, html text etc but I'm not sure. I have never had this problem is regular Java development - usually an error is thrown stating why the content was rejected by the parser.

Here is the xml file I' trying to read in/parse:
<?xml version="1.0" encoding="utf-8"?>
<presentation>

<date></date>
<author>S. Odeyemi </author>
<version>0.1 </version>

<title>Java 101</title>

<introduction>hi people</introduction>

<section>section 1</section>
<section>section 2</section>
<section>section 3</section>
<section>section 4</section>

<link></link>
<image></image>

</presentation>


All the data in the "section" tags were read in successfully, however, the "introduction" and "author" tags returned a empty string. Why is that? Also, "version" tag returned null.

Here's the SAX Handler code if it helps diagnose the problem:
public class TutXMLHandler extends DefaultHandler{
private List<Presentation> presentations;
private Presentation currentPresentation;
private StringBuilder builder;

public List<Presentation> getPresentations(){
return this.presentations;
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
super.characters(ch, start, length);
builder.append(ch, start, length);
}


@Override
public void startDocument() throws SAXException {
super.startDocument();
presentations = new ArrayList<Presentation>();
builder = new StringBuilder();
}


@Override
public void startElement(String uri, String localName, String name,
Attributes attributes) throws SAXException {
super.startElement(uri, localName, name, attributes);
if (localName.equalsIgnoreCase(BasePresentationParser .PRESENTATION)){
//create a presentation object as soon as we
//detect a presentation tag in the xml.
this.currentPresentation = new Presentation();
}
if (localName.equalsIgnoreCase(BasePresentationParser .SECTION) & this.currentPresentation.getSections() == null){
//create a section List object and add to presentation as soon as we
//detect the first section tag in the xml.
this.currentPresentation.setSections(new ArrayList<String>());
}
}

@Override
public void endElement(String uri, String localName, String name)
throws SAXException {
super.endElement(uri, localName, name);
if (this.currentPresentation != null){
//TODO: more attributes still need to be added
if (localName.equalsIgnoreCase(BasePresentationParser .TITLE)){
currentPresentation.setTitle(builder.toString());
} else if (localName.equalsIgnoreCase(BasePresentationParser .LINK)){
currentPresentation.setLink(builder.toString());
}
else if (localName.equalsIgnoreCase(BasePresentationParser .INTRODUCTION)){
currentPresentation.setIntroduction(builder.toStri ng());
}
else if (localName.equalsIgnoreCase(BasePresentationParser .SUB_TITLE)){
currentPresentation.setSubTitle(builder.toString() );
} else if (localName.equalsIgnoreCase(BasePresentationParser .AUTHOR)){
currentPresentation.setAuthor(builder.toString());
} else if (localName.equalsIgnoreCase(BasePresentationParser .SECTION)){
currentPresentation.getSections().add(builder.toSt ring());
currentPresentation.setAuthor(builder.toString());
} else if (localName.equalsIgnoreCase(BasePresentationParser .PRESENTATION)){
presentations.add(currentPresentation);
}
builder.setLength(0);
}
}

}

Thanks in advance for all help!!
10 years ago
Hi there,

I'm trying to deploy an ear file that has been deployed & tested on a WAS 4.0 installation. We are now moving on to WAS 5.0 and I'm trying to port this existing application to WAS 5.0. This is the stack trace for the error I'm getting...

---- Begin backtrace for nested exception

com.ibm.etools.archive.exception.DeploymentDescriptorLoadException: META-INF/application.xml

Stack trace of nested exception:

com.ibm.etools.archive.exception.ArchiveRuntimeException: Invalid binaries path: /apps/websphere5/wcd04/installedApps/netdmgr

_d04/gth.ear

at com.ibm.etools.archive.impl.LoadStrategyImpl.checkLoosePathsValid(LoadStrategyImpl.java:492)

at com.ibm.etools.archive.impl.LoadStrategyImpl.setLooseArchive(LoadStrategyImpl.java:477)

at com.ibm.etools.archive.impl.DirectoryArchiveLoadStrategyImpl.getLooseArchive(DirectoryArchiveLoadStrategyImpl.java

:40)

at com.ibm.etools.archive.impl.LoadStrategyImpl.primGetResourcesPath(LoadStrategyImpl.java:157)

at com.ibm.etools.archive.impl.LoadStrategyImpl.initializeResourceSet(LoadStrategyImpl.java:369)

at com.ibm.etools.archive.impl.LoadStrategyImpl.getResourceSet(LoadStrategyImpl.java:221)

at com.ibm.etools.archive.impl.LoadStrategyImpl.getMofResource(LoadStrategyImpl.java:349)


Any help will be appreciated.

Thanks,
Siju
16 years ago

Originally posted by Jofer Chan:
how to write codes to read data from db file?


Hmmm.. I'm a little perplexed by this db file as well. I have just bought and downloaded my assignment. I'll take a closer look and share my thoughts here soonish.
Hi Kathy Sierra!
Just wanted to say Hi, I've never spoken to a Java celebrity before!
I've been a Java/J2EE Developer (SCJP, SCWCD and studying for SCD & SCBCD)in the UK for about a year now and I'm waiting on your book (Amazon.co.uk on the 30th of Sept). I can't wait to pass it.
Again thanks for the book!!!
--Siju