java.net.MalformedURLException: unknown protocol: c

Hi EveryBody

I am reading a file which consist of space in its name. The location of the file is

C:/Documents and Settings/venkatesh/XMLtest/ListPageDisplayPropertiesMapping.xml

The exception that i am getting is attached at the end of this message for reference. Simplest thing that can be done is i can change the directory name so that there are no spaces. However this file path is takem dynamically. That is this application can run on both unix and windows. Hence the application when compiled, the executables are placed at user's home directory.

Is there a way by which i can encode the file path such that whitespaces are taken care.

Thanks for the help

S venkatesh

[2004-11-05 13:06:31 ] <main> com.webobjects.foundation.NSForwardException for java.net.MalformedURLException: unknown protocol: c

at java.net.URL.<init>(URL.java:586)

at java.net.URL.<init>(URL.java:476)

at java.net.URL.<init>(URL.java:425)

at org.apache.xerces.impl.XMLEntityManager.startEntity(XMLEntityManager.java:807)

at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(XMLEntityManager.java:753)

at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(XMLDocumentScannerImpl.java:260)

at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:499)

at org.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:581)

at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)

at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1114)

at com.webobjects.appserver.xml._private._MappingModel.mappingModelWithXMLFile(_MappingModel.java:405)

at com.webobjects.appserver.xml._private._WOXMLMappingDecoder.<init>(_WOXMLMappingDecoder.java:121)

[1848 byte] By [venkatesh@effigent.net] at [2007-9-30 21:34:13]
# 1

The problem with the unknown protocol, is that 'c' is not a protocol, you need something like http, ftp or file.

In your case that would be:

file:/C:/Documents and Settings/venkatesh/XMLtest/ListPageDisplayPropertiesMapping.xml

I don't know if this works with spaces in directory names, but I hope I' ve helped with the protocol.

Nick_Stolwijk at 2007-7-7 3:05:28 > top of Java-index,Administration Tools,Sun Connection...
# 2
I would suggest file://C: etc.
BIJ001 at 2007-7-7 3:05:28 > top of Java-index,Administration Tools,Sun Connection...
# 3

Thanks for the inputs. And it works.

Just for my knowledge i would like to understand this. Why does protocol need to be specified when there is an empty space in the directory name?

I copied the file to a location where there is no space in the directory. Without specifying the directory name it works. However as suggestedwhen there is a spce in the directory name, it requires protocal name like mentioned below :

file:/C:/Documents and Settings/venkatesh/XMLtest/ListPageDisplayPropertiesMapping.xml

So what does the protocol definition has to do with space in the file name?

venkatesh@effigent.net at 2007-7-7 3:05:28 > top of Java-index,Administration Tools,Sun Connection...
# 4

The protocol should be specified. Under some circumstances the class appears to be able "guess" it, but not always. To be on the secure side, specify it.

Your browser alse guesses the protocol part if you do not specify it. But when you type

ftpsearch.unit.no

instead of

http://ftpsearch.unit.no

you mislead your browser into guessing it as a ftp URL.

BIJ001 at 2007-7-7 3:05:28 > top of Java-index,Administration Tools,Sun Connection...
# 5

I'm not sure that this is the right forum for my question - but I had a question similar to the one above for a menu item in javascript.

I am trying to direct my users to a shared drive/folder from a menu item. The portion of my menu is:

addmenu(menu=["docs",

,,120,1,"",style1,,"left",effect,,,,,,,,,,,,

,"Documentation",href="X:\\Shared Drive\\Target Folder",,,1

Since there is a space in the folder name, it's not reading the entire name - just stops after "Shared".

I tried changing the 3rd line to:

,"Documentation",href="file:\\X:\\Shared Drive\\Target Folder",,,1

but that still did not direct me to the correct file.

Any suggestions?

Thanks.

javascript at 2007-7-7 3:05:28 > top of Java-index,Administration Tools,Sun Connection...
# 6

Hi All,

I got the same problem with protocol c. Your answer was helping me very good.

It validates. Only, for some reason not good.

I keep getting the message:

Parsing error: Document root element "MyRootTag", must match DOCTYPE root "null".

Parsing error: Document is invalid: no grammar found.

When I validate it by using XMLSPY (the XML and the XSD), all validation is correct. Not with this version.

I got the example from IBM site:

public static void main(String args[]) {

File docFile = new File(args[0]);

try {

DOMParser parser = new DOMParser();

parser.setFeature("http://xml.org/sax/features/validation", true);

parser.setProperty(

"http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",

"args[1]");

ErrorChecker errors = new ErrorChecker();

parser.setErrorHandler(errors);

System.out.println(args[0]);

System.out.println(args[1]);

parser.parse(args[0]);

} catch (Exception e) {

System.out.print(e);

System.out.print("Problem parsing the file.");

}

}

This is the reference:

http://www.digilife.be/quickreferences/PT/Validating%20XML.pdf

What are these errors saying?

Please advice.

Thanks in advance.

Henk.

hessie at 2007-7-7 3:05:28 > top of Java-index,Administration Tools,Sun Connection...
# 7

Notice the forward slashes in reply 1.

If your having troubles with spaces, replace them with %20 and in the case of some rmi situations %%20

Also if you don't want to deal with making up a URL or URI you can use File.toURI like this:

public static void main(String[] args)

{

File docFile = new File(args[0]);

try {

System.out.println(docFile.toURI());

} catch (Exception e) {

System.out.print(e);

System.out.print("Problem parsing the file.");

}

}

asbolute path

C:\Javafem\mpowered>java test.URITest "C:\Documents and Settings\cutex1.HYPERNEX

INC\My Documents\data management.sxw

file:/C:/Documents%20and%20Settings/cutex1.HYPERNEXINC/My%20Documents/data%20man

agement.sxw

relative path

C:\Javafem\mpowered>java test.URITest "..\..\Documents and Settings\cutex1.HYPER

NEXINC\My Documents\data management.sxw

file:/C:/Javafem/mpowered/../../Documents%20and%20Settings/cutex1.HYPERNEXINC/My

%20Documents/data%20management.sxw

-

Heink, you have a problem with your xml document .

Martin3 at 2007-7-7 3:05:28 > top of Java-index,Administration Tools,Sun Connection...
# 8

I too had the same issue. On sepcifiying the url with 'file:\\', it works fine. But the issue here is that it is not understood in Unix environment. It says

"

Problem accessing the absolute URL "file:\/opt/app/dynamo/eccdoc". java.io.FileNotFoundException: \/opt/app/dynamo/eccdoc (No such file or directory) "

I am importing the file using <c:import>.

Any help?

Thanks in advance,

John

haikenz at 2007-7-7 3:05:28 > top of Java-index,Administration Tools,Sun Connection...
# 9
What is wrong with this? file:// is for the protocol and past the third / we have the file name. "file:///opt/app/dynamo/eccdoc"
BIJ001 at 2007-7-7 3:05:28 > top of Java-index,Administration Tools,Sun Connection...