about bookpedia plug-in development

Any trouble you encounter with the Pedias, here's the place to ask for help.
Post Reply
djhan
Addicted to Bruji
Addicted to Bruji
Posts: 27
Joined: Tue Nov 28, 2006 8:55 pm

about bookpedia plug-in development

Post by djhan »

Hello, I'm DJ.HAN (I can't write English well, sorry)

I'm not professional programmer. (I only know about php or javascript) But I need a bookpedia search plug-in for me, so I downloaded source from http://www.bruji.com/plugins/. Also I read a thread about development.

Then I tried build with sample source. I open the project in Xcode, then put bookpedia App to build>debug folder. next, I push build and go button, but it's failed. Error log is followin as ;

Running custom shell script (2errors)
mkdir: /Users/djhan/Downloads/sampleplugin/build/Debug/DVDpedia.app/Contents: No such file or directory
cp: /Users/djhan/Downloads/sampleplugin/build/Debug/DVDpedia.app/Contents/Plug-ins: No such file or directory

Ii seemed that sample plugin source is made for dvdpedia. How can I change the setting to bookpedia, and build it?
Please answer my question, Thanks.
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: about bookpedia plug-in development

Post by Conor »

Hi DJ.HAN,

The sample plug-in is set for DVDpedia. Here is one for Bookpedia.
djhan
Addicted to Bruji
Addicted to Bruji
Posts: 27
Joined: Tue Nov 28, 2006 8:55 pm

Re: about bookpedia plug-in development

Post by djhan »

I downloaded samplepluginbook.zip file.

But I see same message too. xcode show message following as ;

mkdir: /Users/djhan/Desktop/SamplePluginBook/build/Release/DVDpedia.app/Contents: No such file or directory
cp: /Users/djhan/Desktop/SamplePluginBook/build/Release/DVDpedia.app/Contents/Plug-ins: No such file or directory

Please link proper file. or please teach me how can I set this source file as bookpedia plugin.
Thanks, good luck
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: about bookpedia plug-in development

Post by Conor »

Try the above download again and it should be fixed. Otherwise under "Target" on the left hand side expand sample and double click the "Quit Copy Launch" phase and change the first line taht says PROGRAM="DVDpedia" to PROGRAM="Bookpedia".
djhan
Addicted to Bruji
Addicted to Bruji
Posts: 27
Joined: Tue Nov 28, 2006 8:55 pm

Re: about bookpedia plug-in development

Post by djhan »

Thanks for your support. Now, I try to making plugin for aladdin (Korean internet bookstore like Amazon. http://www.aladdin.co.kr).

But I have a big problem..... aladdin search form like as;

http://www.aladdin.co.kr/search/wsearch ... earchWord=%@

problem is that aladdin site wasn't support UTF-8. aladdin is euc-kr encoding.

I found searchstring variable declaration in sample code.

> NSMutableString *searchString = [NSMutableString string];

I think utf-8 is default encoding. But I don't know about how convert searchstring variable to euc-kr encoding.
(I am not professional programmer. Real amateur)

Also, aladdin return HTML code as euc-kr. How I can convert it to UTF-8?

Please help me. Thanks, good luck.
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: about bookpedia plug-in development

Post by Conor »

To change the encoding look towards the last method in the plug-in called connectionDidFinishLoading: In that method you will find:

Code: Select all

[[[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding] autorelease]

change the encoding there to: NSJapaneseEUCStringEncoding or NSUnicodeStringEncoding or NSUTF32StringEncoding. I am not sure which one will work for EUC-KR encoding. I am hoping it will be compatible with the Japanese EUC version.

Also in resultNumber: look for the encoding and change it there as well to match.

Code: Select all

NSString *results = [[[NSString alloc] initWithData:[NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil] encoding:NSISOLatin1StringEncoding] autorelease];
Once you get the reading encoding correct you should be able to pass it to the plug-in without converting it, as the Pedias will take care of using the most appropriate encoding. e.i. UTF-8 or 16 if necessary.
djhan
Addicted to Bruji
Addicted to Bruji
Posts: 27
Joined: Tue Nov 28, 2006 8:55 pm

Re: about bookpedia plug-in development

Post by djhan »

Hello, I'm DJ.HAN.
Thanks for your support.

encoding:NSUTF8stringEncoding

to

encoding:-2147481280

Now, I can get euc-kr HTML pages. Thanks!

But It was failed korean keyword search yet..... keyword must be converted utf-8 to euc-kr!

I think that it need to be changed encoding in this sentence;

NSString *httpRequest = [NSString stringWithFormat:@"http://www.aladdin.co.kr/search/wsearch ... earchWord=%@", searchString];

maybe I was wrong.... anyway, How can I converted keyword encoding to euc-kr?
I need your help. Please help me. Thanks Good Luck!
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: about bookpedia plug-in development

Post by Conor »

The URL specifications don't allow for other encodings. What you need to do is add the line that encodes a URL that has non ASCII characters into percent encoding, right before creating the httpRequest string encode the keyword with:

Code: Select all

searchString = [searchString stringByAddingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding];
That should work, otherwise try:

Code: Select all

searchString = [searchString stringByAddingPercentEscapesUsingEncoding:-2147481280];
djhan
Addicted to Bruji
Addicted to Bruji
Posts: 27
Joined: Tue Nov 28, 2006 8:55 pm

Re: about bookpedia plug-in development

Post by djhan »

Thanks!
I make build of aladdin plugin. You can get the plugin in here;

http://www.kbdmania.net/images/mac/aladdin.plugin.zip

It's not perfect. I don't know how can using regular expression in xcode. So, you may get dirty text in summary, or comments.
Anyway it work... :-)

Also, source is here;

http://www.kbdmania.net/images/mac/aladdin_source.zip

in this source, problem is it.

Code: Select all

[cleanString replaceOccurrencesOfString:@"<BR>" withString:@"\n" options:NSCaseInsensitiveSearch range:NSMakeRange(0,[cleanString length])];
~~~~~ many of cleanString sentence ~~~~
[cleanString replaceOccurrencesOfString:@"</Font>" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0,[cleanString length])];
[cleanString replaceOccurrencesOfString:@"<font color=#639A9C>" withString:@"" options:NSCaseInsensitiveSearch 
I wanna change these sentences to this form;

Code: Select all

[cleanString replaceOccurrencesOfString:@"<[a-z0-9]>" withString:@"\n" options:NSCaseInsensitiveSearch range:NSMakeRange(0,[cleanString length])];
But I don't know how to using regular expression in cocoa. How can I do using replacement patterns?
(I'm really amateur, sorry :oops: )

Thanks for your support. Good Luck!
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: about bookpedia plug-in development

Post by Conor »

Cocoa's NSString sadly does not have regular expression support. But you can add it to your plug-in by adding the following two files CSRegex.h and CSRegex.m (use new file under the file menu) you copy the contents for each file from (http://www.cocoadev.com/index.pl?CSRegex). This file will extend NSString to support regcomp()/regexec() functions available in the BSD. You can then do a while loop on a match and add the replace inside:

Code: Select all

NSString *nextMatch;
while (nextMatch = [cleanString substringMatchedByPattern:@"[a-z0-9]"]) {
[cleanString replaceOccurrencesOfString: nextMatch withString:@"\n" options:NSCaseInsensitiveSearch range:NSMakeRange(0,[cleanString length])];
}
I personally have never used CSRegex, plus I made that and typed the above here on the spot, so it might not work, but it's a starting point for regular expressions.

Other options:
http://www.mactech.com/articles/mactech ... pressions/
http://sourceforge.net/projects/objpcre
http://regexkit.sourceforge.net/
http://www.cocoadev.com/index.pl?RegularExpressions

You might say you are a novice, but creating a plug-in is no easy matter – congratulations. The even better news is you can tweak it to fit your exact needs.
djhan
Addicted to Bruji
Addicted to Bruji
Posts: 27
Joined: Tue Nov 28, 2006 8:55 pm

Re: about bookpedia plug-in development

Post by djhan »

Thanks for your support.

but your code have a problem.

Code: Select all

NSString *nextMatch;
while (nextMatch = [cleanString substringMatchedByPattern:@"[a-z0-9]"]) {
[cleanString replaceOccurrencesOfString: nextMatch withString:@"\n" options:NSCaseInsensitiveSearch range:NSMakeRange(0,[cleanString length])];
}
if cleanstring is NSmutablestring, this code wasn't work.

I'll trying find other way. Thanks, really thanks for your support and teaching. Good luck for you!
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: about bookpedia plug-in development

Post by Conor »

Why wouldn't it work? NSMutableString is a subclass of NSString, so it would inherit all the extension that are added to NSString such as the regex capabilities.

This is one of the confusing aspects of Cocoa. You have to look at the inheritance of a class to know all the methods it can perform. For example NSMutableString inherits from NSString and NSString from NSObject (every class inherits from NSObject, it's the root class). So NSMutableString can do all the NSMutableString methods, plus all the NSString methods, plus all the NSObject methods.

The CSRegex is a category of NSString that extends NSString by adding more methods to that class. NSMutableString would inherit all those extensions as well.

Let me the error you get and I might be able to narrow down the solution. As I mentioned I wrote the code here and do not have CSRegex, but in theory what I wrote should work. If you let me know the error maybe there is something new I can learn here too.
djhan
Addicted to Bruji
Addicted to Bruji
Posts: 27
Joined: Tue Nov 28, 2006 8:55 pm

Re: about bookpedia plug-in development

Post by djhan »

Hello, I'm DJ.HAN.
Firstly, please DL my source code.

I add your source for getting comments part. like as ;

Code: Select all

	NSString *comments = [results stringBetween:@"<div id=\"bodyDescription\">" and:@"</DIV>"];
	if (comments) {
		// Remove HTML
		
		NSMutableString *cleanString = [NSMutableString stringWithString:comments];
		NSString *nextMatch;
		while (nextMatch = [cleanString substringMatchedByPattern:@"[a-z0-9]"]) {
			[cleanString replaceOccurrencesOfString: nextMatch withString:@"\n" options:NSCaseInsensitiveSearch range:NSMakeRange(0,[cleanString length])];
		}
		[returnData setObject:cleanString forKey:@"comments"];
	}
Then I build&go, xcode show me warning message under line of "NSMutableString *cleanString = [NSMutableString stringWithString:comments];". The message is....

Warnign : 'NSmutableString' may not respond to '-substringMatchedByPattern'
(Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments.)


What's wrong with my source code? If you can help me, I'll very happy :D
Thanks, Good Luck!
User avatar
Conor
Top Dog
Posts: 5346
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: about bookpedia plug-in development

Post by Conor »

You did not include the CSRegex files that extend the NSString methods to do regular expressions. I have included them to your project. Download it and you will be able to add the code now.
djhan
Addicted to Bruji
Addicted to Bruji
Posts: 27
Joined: Tue Nov 28, 2006 8:55 pm

Re: about bookpedia plug-in development

Post by djhan »

Thanks, thanks for your support!
I was success strip some HTML tag using regular expression. Thanks!
So, the aladdin plugin 0.3.5 is here ;

http://www.kbdmania.net/images/mac/alad ... .0.3.5.zip

now, you can test this plugin. (some korean book have english word. e.g) test, cinema ...)

and rebuilt source was uploaded same place, same name.
Anyway, really thanks for your support for korean users. Thanks, Good luck!
Post Reply