I make a basic plugin on netbeans 8.0.2 and I'm a little confused because I want to read the code in some way to provide errors or other notifications to the user you are writing code but not how.
This should print out all the text in all the open windows.
TopComponent tcArray[] = WindowManager.getDefault().findMode("editor").getTopComponents();
for (TopComponent tc : tcArray) {
System.out.println("tc = " + tc);
Collection<? extends FileObject> fileobjs = tc.getLookup().lookupAll(FileObject.class);
for (FileObject fo : fileobjs) {
try {
String text = fo.asText();
System.out.println("text = " + text);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
}
In order to use it you need the following modules added as dependencies.
File System API
Lookup API
Utilities API
Window System API
Related
I am generating emails from an SSIS package using a Script task. During testing, I do not want to really send the email, but drop the message into a folder. In an application, I would use the specifiedPickupDirectory option in the web.config, but SSIS packages do not have a web.config.
Is there a way to send the email to a folder?
Thanks
If you script task is using C# then the following should work. It's similar to how you would change the Web.config to use specifiedPickupDirectory
SmtpClient client = new SmtpClient("my_smtp_host");
client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
client.PickupDirectoryLocation = #"C:\save_email_directory";
client.Send(message);
You may also need to add Network credentials, see link for example
If you use Exchange mail and this library: http://independentsoft.de/ you can create a message and move it into a specific folder.
I do not own this software, but I'm a satisfied user.
Just start here: http://independentsoft.de/exchangewebservices/tutorial/createmessage.html with this example code:
using System;
using System.Net;
using Independentsoft.Exchange;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
NetworkCredential credential = new NetworkCredential("username", "password");
Service service = new Service("https://myserver/ews/Exchange.asmx", credential);
try
{
Message message = new Message();
message.Subject = "Test";
message.Body = new Body("Body text");
message.ToRecipients.Add(new Mailbox("John#mydomain.com"));
message.CcRecipients.Add(new Mailbox("Mark#mydomain.com"));
ItemId itemId = service.CreateItem(message);
}
catch (ServiceRequestException ex)
{
Console.WriteLine("Error: " + ex.Message);
Console.WriteLine("Error: " + ex.XmlMessage);
Console.Read();
}
catch (WebException ex)
{
Console.WriteLine("Error: " + ex.Message);
Console.Read();
}
}
}
}
I am having a HttpUnit code,in which I am trying to access google''s official website.Here is my code:
/** everything you need to start is in the com.meterware.httpunit package **/
import com.meterware.httpunit.*;
/** This is a simple example of using HttpUnit to read and understand web pages. **/
public class Example {
public static void main(String[] params) {
try {
WebConversation wc = new WebConversation();
String url = "https://www.yahoo.com";
WebRequest request = new GetMethodWebRequest(url);
WebResponse response = wc.getResponse(request);
// WebLink httpunitLink = response.getFirstMatchingLink(
// WebLink.MATCH_CONTAINED_TEXT, "HTML" );
// response = httpunitLink.click();
System.out.println("The yahoo main page '" + url + "' contains "
+ response.getLinks().length + " links");
} catch (Exception e) {
System.err.println("Exception: " + e);
}
}
}
I am getting the below exception on running the code.I am using eclipse as IDE.
org.mozilla.javascript.EcmaError: TypeError: Cannot read property "className" from undefined (httpunit#3)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3229)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3219)
at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3235)
at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3254)
at org.mozilla.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:3267)
at org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1324)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:2816)
at script(httpunit:3)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2251)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:161)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:340)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2758)
at org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:172)
at org.mozilla.javascript.Context.evaluateString(Context.java:1132)
at com.meterware.httpunit.javascript.ScriptingEngineImpl.runScript(ScriptingEngineImpl.java:92)
at com.meterware.httpunit.scripting.ScriptableDelegate.runScript(ScriptableDelegate.java:88)
at com.meterware.httpunit.parsing.NekoDOMParser.runScript(NekoDOMParser.java:151)
at com.meterware.httpunit.parsing.ScriptFilter.getTranslatedScript(ScriptFilter.java:150)
at com.meterware.httpunit.parsing.ScriptFilter.endElement(ScriptFilter.java:131)
at org.cyberneko.html.filters.DefaultFilter.endElement(DefaultFilter.java:249)
at org.cyberneko.html.filters.NamespaceBinder.endElement(NamespaceBinder.java:367)
at org.cyberneko.html.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1015)
at org.cyberneko.html.HTMLTagBalancer.endElement(HTMLTagBalancer.java:888)
at org.cyberneko.html.HTMLScanner$SpecialScanner.scan(HTMLScanner.java:2831)
at org.cyberneko.html.HTMLScanner.scanDocument(HTMLScanner.java:809)
at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:478)
at org.cyberneko.html.HTMLConfiguration.parse(HTMLConfiguration.java:431)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at com.meterware.httpunit.parsing.NekoHTMLParser.parse(NekoHTMLParser.java:48)
at com.meterware.httpunit.HTMLPage.parse(HTMLPage.java:271)
at com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:1301)
at com.meterware.httpunit.WebResponse.getFrames(WebResponse.java:1285)
at com.meterware.httpunit.WebResponse.getFrameRequests(WebResponse.java:1024)
at com.meterware.httpunit.FrameHolder.updateFrames(FrameHolder.java:179)
at com.meterware.httpunit.WebWindow.updateFrameContents(WebWindow.java:315)
at com.meterware.httpunit.WebClient.updateFrameContents(WebClient.java:526)
at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:201)
at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:183)
at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158)
at com.meterware.httpunit.WebClient.getResponse(WebClient.java:122)
at Example.main(Example.java:14)
Exception: com.meterware.httpunit.ScriptException: Script '//used for perf beacons in 3pas
rtTop = Number(new Date());
document.documentElement.className += ' jsenabled';
if (!("ontouchstart" in document.documentElement)) {
document.documentElement.className += " no-touch";
}
(function(){var k=13,d=4,j=0,a=document.documentElement,b=[a.className],f,c=navigator.plugins,g=k;if(c&&c.length){f=c["Shockwave Flash"];if(f&&f.description){j=parseInt(f.description.match(/\b(\d+)\.\d+\b/)[1],10)||0}}else{while(g--){try{new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+g);j=g;break}catch(h){}}}b.push("flash-"+j);while(j-->d){b.push("flash-gt"+j)}a.className=b.join(" ")})();
(function(){var j=this,n=/^(on)?load/,b=/^on/,i="addEventListener",f="attachEvent",e="_oc",h="detachEvent",g="removeEventListener",l=j[i],m=j[g],p=j[f],a=j[h],k={},d=0;function c(r,s,q){if(!r||!s){return;}if(n.test(r)){if(!s[e]){var t=++d;s[e]=t;k[t]=s;}}else{if(p&&b.test(r)){p(r,s);}else{if(l){l(r,s,q);}}}}function o(r,s,q){if(!r||!s){return;}if(n.test(r)){var t=s[e];if(t){delete k[t];}}else{if(a&&b.test(r)){a(r,s);}else{if(m){m(r,s,q);}}}}j.OnloadCache={enable:function(){if(l){j[i]=c;j[g]=o;}if(p){j[f]=c;j[h]=o;}},disable:function(){if(l){j[i]=l;j[g]=m;}if(p){j[f]=p;j[h]=a;}},dispatch:function(){var r={type:"load"},q;for(q in k){if(k.hasOwnProperty(q)){k[q](r);}}},reset:function(){k={};}};})();
OnloadCache.enable();
var setJSCookie = true;
(function () {
var cookieName = "FBJSC=";
var cookieValue = "1409123746";
var cookieIndex = document.cookie.indexOf(cookieName);
if(cookieIndex >= 0) {
var oldValue = document.cookie.substr(cookieIndex + cookieName.length, cookieValue.length);
if(cookieValue <= oldValue) {
setJSCookie = false;
}
}
if(setJSCookie) {
document.cookie = cookieName + cookieValue;
}
})();' failed: org.mozilla.javascript.EcmaError: TypeError: Cannot read property "className" from undefined (httpunit#3)
Any help would be greatly appreciated.Thanks.enter code here
As one of the httpunit committers I'd recommend reading the FAQ:
http://httpunit.sourceforge.net/doc/faq.html
JavaScript support of httpunit is limited. The Error you are getting is showing that you ran into JavaScript code that is more complicated than what httpunit can handle. As a work-around you might want to switch off javascript altogether (if that is possible in your use case).
The following is from HttpUnit's developer FAQ:
HttpUnit 1.x support of Javascript is limited. There is a new Javascript engine in development but the development is almost stalled due to limited resources.
To work around the issue you might want to
try the new scripting engine
switch off javascript
if you get an org.mozilla.javascript.EcmAError ... undefined ... find the missing javascript function, implement it and supply the patch for the community see "6. How can I suggest modifications to httpunit?"
I tried so hard for a simple line of code that read a file content from enterprise github with oauth token, but could not find a example of such.
I tried https://github.com/jcabi/jcabi-github, but it does not support enterprise github?(maybe I am wrong)
Now i am trying egit:
GitHubClient client = new GitHubClient("enterprise url");
GitHubRequest request = new GitHubRequest();
request.setUri("/readme");
GitHubResponse response = client.get(request);
Then what? I only saw a getBody, maybe I need to parse it with some kinda json library? It has to be simpler..I am expecting something like: repo.get(url).getContent()
Finally figure out by reading source code..
GitHubClient client = new GitHubClient(YOURENTERPRICEURL);
client.setOAuth2Token(token);
// first use token service
RepositoryService repoService = new RepositoryService(client);
try {
Repository repo = repoService.getRepository(USER, REPONAME);
// now contents service
ContentsService contentService = new ContentsService(client);
List<RepositoryContents> test = contentService.getContents(repo, YOURFILENAME);
List<RepositoryContents> contentList = contentService.getContents(repo);
for(RepositoryContents content : test){
String fileConent = content.getContent();
String valueDecoded= new String(Base64.decodeBase64(fileConent.getBytes() ));
System.out.println(valueDecoded);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
So I am new to GWT and am not sure what the best programming practices are for what I am trying to do. In my web application the user will be able to upload a data file, my application needs to be able to access this file, do some stuff to it, and then let the user download the manipulated file.
So far I have been able to successfully upload a file with an upload servlet with this doPost method:
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
ServletFileUpload fileUpload = new ServletFileUpload(fileItemFactory);
fileUpload.setSizeMax(FILE_SIZE_LIMIT);
List<FileItem> items = fileUpload.parseRequest(req);
for (FileItem item : items) {
if (item.isFormField()) {
logger.log(Level.INFO, "Received form field:");
logger.log(Level.INFO, "Name: " + item.getFieldName());
logger.log(Level.INFO, "Value: " + item.getString());
} else {
logger.log(Level.INFO, "Received file:");
logger.log(Level.INFO, "Name: " + item.getName());
logger.log(Level.INFO, "Size: " + item.getSize());
}
if (!item.isFormField()) {
if (item.getSize() > FILE_SIZE_LIMIT) {
resp.sendError(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE, "File size exceeds limit");
return;
}
String fileName = item.getName();
if (fileName != null) {
fileName = FilenameUtils.getName(fileName);
}
fileName = getServletContext().getRealPath("/uploadedFiles/" + fileName);
byte[] data = item.get();
FileOutputStream fileOutSt = new FileOutputStream(fileName);
fileOutSt.write(data);
fileOutSt.close();
if (!item.isInMemory())
item.delete();
}
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Throwing servlet exception for unhandled exception", e);
throw new ServletException(e);
}
}
When I look in my war folder, the uploadedFiles folder is created successfully and files are put there.
At this point I am a bit stuck, I have been researching but cannot seem to find a clear concise answer on what is the best way for me to access the uploaded files on the client side in order to manipulate them and then allow the user to download them. Maybe I am approaching this wrong, I am not sure. If someone could point me in the right direction or show me some good examples of the right way to do things that would be great, thanks.
To access the file in client side you need a new servlet or the same you are using with a doGet method.
The client should ask for the file via an Anchor or an Image depending on the file type but adding a parameter so as the server is able to identify the file. Normally you can use the name of the FileInput you used for uploading or maybe you could return a tag from the server.
I would recommend to you to take a try to gwt-upload, it would save a lot of time to you.
I solved my problem. When the file was successfully uploaded, I stored the file name. Later I used a RPC to access the file on the server. I passed the file name to the RPC so that it knows what file I am working on, then it looks for that file in the upload folder. So I can create the java file like this,
File file = new File((this.getServletContext().getRealPath("uploadedFiles") + File.separator + fileName));
and manipulate it how I see fit.
In JasperReports Server Pro 4.5, is there any way to force the program to open reports/repository elements in a new browser tab or window?
You should be able to fix that by updating the relevant JavaScript file to force everything to open in a new tab. In JRS 4.5.1 it's line 766 in the file .../jasperserver-pro/scripts/repository.search.actions.js
repositorySearch.RedirectAction.createRunResourceAction = function(resource, inNewTab) {
if (!resource) {
resource = resource ? resource : repositorySearch.model.getSelectedResources()[0];
}
var factoryMethod = repositorySearch.runActionFactory[resource.typeSuffix()];
if (factoryMethod) {
/* return factoryMethod(resource, inNewTab); this was the original */
return factoryMethod(resource, true);
} else {
return new repositorySearch.Action(function() {
alert("Run action for resource type '" + resource.resourceType + "' is not implemented!");
});
}
};
I cannot claim credit for figuring it out. Thanks to Igor Nesterenko for this solution.