Leider verstehe ich nicht sehr viel davon, wenn es um eine Java-Verknüpfung geht. Insbesondere gibt mir mein Matlab bei der folgenden Zeile eine Fehlermeldung:
Error: File: blogpost.m Line: 230 Column: 8
Arguments to IMPORT must either end with ".*"
or else specify a fully qualified class name: "redstone.xmlrpc.XmlRpcClient"
fails this test.
Kann mir jemand dabei helfen, warum diese Zeilen nicht durchlaufen und wozu sie benötigt werden? Ich bedanke mich schon einmal im Voraus. Ich poste im Folgenden noch den kompletten Code des m-files:
Code:
function post_id = blogpost(mfile, dryrun, verbose) % post the html output of publishing an m-file to matlab.cheme.cmu.edu % postid = blogpost('my_mfile.m')
%
% if dryrun is true, no post is run, and the local post-processed html i % opened in a browser.
%
% if verbose is true, there is more output (not supported yet).
%
% you need to create a function called blogCredentials on your Matlab % path that returns the user and password of the user you will submit % the post as, and the server: % function [user, password, server] = blogCredentials() % user = 'your-user-name'; % password = 'secretpassword'; % server = 'http://matlab.cheme.cmu.edu/xmlrpc.php'; % end function
%
% or you will be prompted for that information.
%
% you can specify categories and tags in your m-file with this markup. % categories: category1, category2 % tags: tag1, tag2
%
% you can refer to other posts with this syntax: `:postid: 456`. This will % be converted to a link in the published post (but not in the published % matlab).
%
% you can add a file to be downloaded with `:download: path-to-file`. The % path should be relative to your m-file. Note that this function *assumes* % you are publishing the m-file from the directory where the m-file is.
%
% you can have general markup of :directive:`datastring` as long as you % make a function called wp_directive that handles datastring and returns % the text it should be replaced with.
%
% this function will add a comment to the end of your m-file containing the % postid that was published. If you repost the m-file later, and the postid % is still valid, then the existing post will just be updated.
if ~strcmp(mfile(end-1:end),'.m')
mfile = [mfile '.m'];
end
%% make sure file has been published if mfile is newer than html file % files are published in html
htmlfile = fullfile(pwd, 'html', strrep(mfile,'.m','.html'));
ifexist(htmlfile,'file')
h = dir(htmlfile);
m = dir(mfile);
if m.datenum > h.datenum % we should publish to get latest output
htmlfile = publish(mfile);
end else % file doesn't exist, so we publish it. htmlfile will be an absolute % path
htmlfile = publish(mfile);
end
% assume this is a new post. this is changed when reading the mfile if an % old post_id is found
NEWPOST = true;
%% get title, categories and tags from the mfile text = fileread(mfile);
%% check title % we take the first line if it starts with %% and has something in it.
title_re = '^%% ([^\n]*)\r';
tokens = regexp(text, title_re, 'tokens');
iflength(tokens) == 1 title = tokens{1}{1};
else title = mfile;
end
%% categories
category_re = '% categories:\s*([^\n]*)\r'; [tokens] = regexp(text,category_re, 'tokens');
iflength(tokens) > 1 % there may be zero error('Too many categories matches found') elseiflength(tokens) == 1
categories = regexp(tokens{1},',','split');
categories = categories{1};
end
%% post_id
tokens = regexp(text,'% post_id =\s*(\d*);.*\r','tokens'); iflength(tokens) > 1 error('Too many post_id lines found') elseiflength(tokens) == 1
post_id = tokens{1}{1};
validid = validPostId(post_id);
if validid == true
NEWPOST = false;
else
%stored postid is not valid, it may have been deleted on the blog.
NEWPOST = true;
end end
%% check to make sure each category exists in the blog % wordpress silently drops categories that don't exist % add category if it does not exist. for i = 1:length(categories) category = strtrim(categories{i});
exists = categoryExists(category);
if ~exists
newCategory(category);
end end
%% process html % now we get the html and process it looking for images. we need to upload % each image, get the new url to the image, and replace that in the html % code. We also look for special markups e.g. `postid: 650` that are % replaced by urls to those posts.
%% handle the Source % this gets mangled by the substitutions below, so we save it here, replace % it so nothing is changed, and put it back later
reg = '##### SOURCE BEGIN #####(.*)##### SOURCE END #####';
[match] = regexp(htmltext,reg,'match');
source_code = match{1};
%% now handle images
reg = ['<img .*?src="'...% up to src="
'([^"]*)'...% grab the src filename
'".*?>']; % the rest of the link [tokens] = regexp(htmltext,reg,'tokens');
for i=1:length(tokens)
%matches{i}
imgfile = tokens{i}{1};
% upload new image, and get url if ~dryrun
url = newMediaObject(fullfile(publish_location,imgfile));
else % figure location for a dryrun
url = fullfile(publish_location,imgfile);
end % replace the old link with the wordpress url
htmltext = strrep(htmltext,imgfile,url);
end
%% handle any literal text % we have to find <pre>text</pre> % we will find and replace these with a UUID, store that UUID in a % Containers.map so we can substitute the text back in later.
reg = '<pre>([^<]*)</pre>';
[matches] = regexp(htmltext, reg, 'match');
literal_map = containers.Map();
for i=1:length(matches)
uuid = char(java.util.UUID.randomUUID);
literal_map(uuid) = matches{i};
% now replace matches{i} with uuid
htmltext = strrep(htmltext, matches{i}, uuid);
end
for i = 1:length(tokens)
directive = tokens{i}{1};
datastring = tokens{i}{2};
% construct string of command to evaluate wp_directive(datastring) % all the wp_cmd functions are in ./extensions
runcmd = sprintf('wp_%s(''%s'')', directive, datastring);
html = eval(runcmd);
% now replace the matched text with the html output
htmltext = strrep(htmltext, matches{i}, html);
% now end
%% put literal text back in
keys = literal_map.keys();
for i=1:length(keys)
htmltext = strrep(htmltext,keys{i}, literal_map(keys{i}));
end
%% finally, put unmodified source code back in.
htmltext = strrep(htmltext, uuid_source_code, [' ' source_code ' ']);
%% now we get credentials and the client ifexist('blogCredentials','file') == 2 [user,password,server] = blogCredentials();
else
user = input('Enter your username: ','s');
password = passwordUI();
server = input('Enter blog server: ', 's');
end
%% create the post structure
post = java.util.HashMap();
post.put('title',title);
post.put('description',htmltext);
if ~isempty(categories)
post.put('categories',categories);
end
if ~isempty(tags)
post.put('mt_keywords',tags);
end
%% finally the posting action if dryrun
web(tmpfile) edit(tmpfile) pause(5) else if NEWPOST == true
post_id = client.invoke('metaWeblog.newPost',{1,user,password,post,true});
p = getPost(post_id);
fid = fopen(mfile,'a+');
fprintf(fid,'\r%% post_id = %s; %%delete this line to force new post;\r',char(post_id)); fprintf(fid,'%% permaLink = %s;\r',char(p.get('permaLink'))); fclose(fid);
else % edit post
result = client.invoke('metaWeblog.editPost',{post_id,user,password,post,true});
if result ~= 1 disp(result) end end end
Danke flashpixx für deine Antwort. Ich will den Code jedoch vorher mit Matlabs "publish"-Befehl kompilieren. Dies formatiert dann den Code mit Textstellen, Absätzen, Code, Tex-kompilierten Formeln etc.
Ich will also nicht nur ein Stück Code veröffentlichen, sondern einen kompletten Blogeintrag wie zB hier zu sehen:
Danke flashpixx für deine Antwort. Ich will den Code jedoch vorher mit Matlabs "publish"-Befehl kompilieren. Dies formatiert dann den Code mit Textstellen, Absätzen, Code, Tex-kompilierten Formeln etc.
Ich kopiere den Code einfach in den Blogeintrag und sage vorher, welche Sprache es ist. Mein System unterstützt eine Vielzahl an Layoutmechanismen für die unterschiedlichsten Sprachen. In dem Mex Eintrag z.B. C++ und Matlab, LaTeX Codes werden dann direkt als Bild gerendet.
Der Fehler tritt in diesen Zeilen auf (es wäre durchaus hilfreich gewesen, wenn Du diese Zeilen einmal direkt angegeben hättest, als den kompletten Code):
[code]
import redstone.xmlrpc.XmlRpcClient;
client = XmlRpcClient(server,0);
[/quote]
Ohne eine Garantie, dass es funktioniert, sollte dies so funktionieren:
[code]
client = redstone.xmlrpc.XmlRpcClient(server,0);
[/code]
Ich rate aber dazu, dass Du nicht direkt von Matlab einen Artikel pushst, sondern eben den Artikel mit einer DTP Software oder im der Blogadministration mit einer entsprechenden Formatierung eingibst. Gerade bei Quellcode finde ich passendes Syntaxhighlighting und Zeilennummerierung unerlässlich
Erneut Danke an dich, flashpixx. Ich habe die Funktion bei Wordpress nicht gefunden, dass er Matlab-Code erkennt und kompiliert.
Ich fühle auch, dass ich sehr nah an der Lösung bin. Der Code läuft auch durch und ich verstehe mehr und mehr Teile davon. Jedoch bereiten mir die anfangs erwähnten Zeilen immer noch Probleme. Die Fehlermeldung lautet:
Zitat:
Undefined variable "redstone" or class "redstone.xmlrpc.XmlRpcClient".
Error in blogpost (line 232)
client = redstone.xmlrpc.XmlRpcClient(server,0);
Kann mir jemand sagen, wie ich diesen Code zum Laufen bringen kann?
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.