basically I just want to know, if there are ways on how to export excel sheet file in Podio with the comments section included in a certain app using API.
There is no direct API call to export to excel along with comments. Export work on Items and Apps
There is a work around to do this.
1. Make a CommentAPI call as per code attached, you can get all the comments on Item, so that you can export them to your excel programmatically.
public class APICall implements Serializable {
public static void main(String as[]){
APICall apiObj = new APICall();
apiObj.apicall();
}
/**
*
*/
public void apicall()
{
try{
System.out.println("inside");
ResourceFactory resourceFactory = new ResourceFactory(new OAuthClientCredentials("<WS NAME>","<Your authkey>"),new OAuthUsernameCredentials("<username>", "<Password>"));
CommentAPI capi = new CommentAPI(resourceFactory);
Reference ref= new Reference(ReferenceType.ITEM,561530318);
List<Comment> cmts = capi.getComments(ref);
for(Comment e : cmts )
System.out.println(e.getValue());
Related
So I just started playing around with JDA API trying to create a little /info command which looked like shown below.
Issue: Unfortunately the bot does not react when I type /info.
While I was debugging, I found out, that the Info command never get's called and I will explain why later, after showing you the 3 classes that are involved in this problem.
public class InfoCommand extends Command {
public InfoCommand(String name) {
super(name);
}
#Override
public void handle(MessageReceivedEvent event, String... params) {
EmbedBuilder builder = new EmbedBuilder();
builder.setTitle("Test Title");
builder.setDescription("Test Description" );
builder.setFooter("Created by t0gepi");
builder.setColor(0xf45642);
event.getChannel().sendTyping().queue();
event.getChannel().sendMessageEmbeds(builder.build()).queue();
}
}
It has a method handle which will be called by a CommandManager, whenever /info is typed in the discord server.
So far so good.
Now the Main method is also quite simple. It just starts the bot and adds the CommandManager as a Listener to JDA:
public class Main {
public static JDA jda;
public static void main(String[] args) throws LoginException {
ResourceManager.init();
jda = JDABuilder.createDefault(ResourceManager.getProperty("discord.bottoken")).build();
jda.getPresence().setStatus(OnlineStatus.IDLE);
jda.getPresence().setActivity(Activity.playing("Sleeping"));
try {
jda.awaitReady();
} catch (InterruptedException e) {
e.printStackTrace();
}
CommandManager commandManager = new CommandManager();
commandManager.addCommand(new InfoCommand("info"));
jda.addEventListener(new CommandManager());
}
}
Lastly, let's get to the CommandManager:
public class CommandManager extends ListenerAdapter {
private Set<Command> commands;
public CommandManager(){
this.commands = new HashSet<>();
}
public void addCommand(Command command){
commands.add(command);
}
#Override
public void onMessageReceived(#NotNull MessageReceivedEvent event) {
String[] msg = event.getMessage().getContentRaw().split(" ");
String prefix = ResourceManager.getProperty("command.prefix");
String[] params = null;
if(!msg[0].startsWith(prefix)){
return;
}
if(msg.length > 1){
params = Arrays.copyOfRange(msg,1,msg.length);
}
Iterator<Command> iterator = commands.iterator();
Command command;
while(iterator.hasNext()){
command = iterator.next();
if(command.getAliases().stream().anyMatch(alias -> msg[0].equalsIgnoreCase(prefix + alias))){
command.handle(event, params);
return;
}
}
// Do nothing here if command wasn't found.
}
}
Now let's get to the actual issue, why does the InfoCommands handle method not get called? Keep in mind that
InfoCommand has bin initialized and added to the CommandManager
The CommandManagers onMessageReceived method is in fact being called when a message is typed
As I was debugging, I found out why but could not find an explanation to it.
The reason why the handle method of InfoCommand does not get called, is because as to the time when onMessageReceived gets called, the CommandManagers set of commands is empty.
Why is that? I added the InfoCommand in the beginning right?
When I added the InfoCommand in the beginning, the set of commands had a size of 1. All good. But when onMessageReceived got called, the set of Commands suddenly had a size of 0, which means that the Iterator doesn't have anything to iterate over.
Why is that? I furthermore found out the following:
As to the time where I initialized the CommandManager, the CommandManager had a different memory adress than when it's onMessageReceived method got called.
So somehow, JDA must have created another new instance of CommandManager and used that, instead of my instance, right?
I hope someone understands this and let me know if you have any questions :)
Thanks for reading that far and if you'd like, you can take a better look at all the files in this Project here. There really aren't much more.
You are creating a new instance of your command manager when you register it:
jda.addEventListener(new CommandManager());
Instead, you should just pass in the instance you previously created:
CommandManager commandManager = new CommandManager();
commandManager.addCommand(new InfoCommand("info"));
jda.addEventListener(commandManager);
Fairy new to programming, 2nd post here. I'm attempting to make a personal project that takes an article(like a reddit article) and saves it to an mp3 or wav file that can be burned to a CD and listened to.
I am using the java JSoup library to grab the paragraph elements from the article and save them to a .txt file, which is working. I am also using java swing with freetts(currently in a separate project) to convert text to speech, which is also working.
My best guess as to the next step is to get the freetts to save the text to an audio file. Im trying to use a method called dumpAudio that i found on the freetts site, and i cant get it to work. So my question is,what am i doing wrong?
Here is my attempt at this(i only included the freetts code for brevity):
public class MyRedditProject extends javax.swing.JFrame {
// code is from https://www.youtube.com/watch?v=swuYhvwHw9w
/**
* Creates new form RedditProject
*/
public MyRedditProject() {
initComponents();
}
#SuppressWarnings("unchecked")
private static final String VOICENAME = "kevin16";
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Voice voice;
VoiceManager vm = VoiceManager.getInstance();
voice = vm.getVoice(VOICENAME);
voice.allocate();
try
{
voice.speak(jTextArea1.getText());
//trying to use dumpAudio to save text to audio file. I found the
//dumpAudio method on the freetts site
vm.dumpAudio("C:\\Users\\david\\Documents\\Reddit_Project\\dumpAudio.wav");
}
catch(Exception e)
{
}
I am creating a utility that will add a multi-line text field just below the last line of text in an existing PDF document. This will be used for people who want to add comments to a report that is generated from another system.
I followed the examples from the iText book, and also looked at this SO question: Get the exact Stringposition in PDF
So now I've got a method that parses the last page of the document and a custom listener that finds the coordinates of the text I'm looking for.
Here is my code parsing method:
private void parsePdfPage2(String src, int pageNum) throws IOException {
PdfReader reader = new PdfReader(src);
RenderListener listener = new MyTextRenderListener();
PdfContentStreamProcessor processor = new PdfContentStreamProcessor(listener);
PdfDictionary pageDic = reader.getPageN(pageNum);
PdfDictionary resourcesDic = pageDic.getAsDict(PdfName.RESOURCES);
processor.processContent(ContentByteUtils.getContentBytesForPage(reader, pageNum), resourcesDic);
}
And here is the listener:
public class MyTextRenderListener implements RenderListener {
#Override
public void beginTextBlock() {}
#Override
public void endTextBlock() {}
#Override
public void renderImage(ImageRenderInfo renderInfo) {}
#Override
public void renderText(TextRenderInfo renderInfo) {
// Check if this is the text marker
String text = renderInfo.getText();
if (text.equalsIgnoreCase("Comments")) {
// Found it
LineSegment ls = renderInfo.getBaseline();
System.out.println("Found at X: " + ls.getBoundingRectange().getX() +
", Y: " + ls.getBoundingRectange().getY());
}
}
}
However, now I need to send the found LineSegment object (or the individual coordinates) back to the original parsing method. Of course I could write the values to disk and read it in the parsing method, but that seems horrible. I'm pretty sure there is a more elegant way to achieve this and would appreciate pointers.
This is an old question but still:
You could save the results of the listener into a private list (in the class).
After that what's left to add is a public method (getResults()) which returns the list.
Simply call getResults after the processContent call since the synchronous nature of the processContent method guarentees the list to be filled correctly.
The only problem with this solution is that listeners can't be reused.
We have AbstractContributionFactorys like these:
final AbstractContributionFactory contributions = new AbstractContributionFactory("org.acme.mainMenu", null) {
#Override
public void createContributionItems(final IServiceLocator serviceLocator,
final IContributionRoot contributionRoot) {
String subMenuId ="org.acme.subMenu";
final MenuManager subMenu = new MenuManager("Sub menu", subMenuId );
contributionRoot.addContributionItem(subMenu, AlwaysEnabledExpression.INSTANCE);
menuService.addContributionFactory(new AbstractContributionFactory("menu:" + subMenuId, null) {
#Override
public void createContributionItems(final IServiceLocator serviceLocator1,
final IContributionRoot additions) {
additions.addContributionItem(new ActionContributionItem(new Action("Sub action") {
}), AlwaysEnabledExpression.INSTANCE);
}
});
}
};
menuService.addContributionFactory(contributions);
This code worked perfectly in Eclipse 3.x, but stopped working in E4. So while searching for the bug we found a lot uncommented code in the E4 framework, as much as two blocks in WorkbenchMenuService.addContributionFactory(...) alone. What I assume produces the bug is:
// // OK, now update any managers that use this uri
// for (Map.Entry<ContributionManager, MenuLocationURI> entry :
// managers.entrySet()) {
// MenuLocationURI mgrURI = entry.getValue();
// if (mgrURI.getScheme().equals(location.getScheme())
// && mgrURI.getPath().equals(location.getPath())) {
// ContributionManager mgr = entry.getKey();
// populateContributionManager(mgr, mgrURI.toString());
// mgr.update(true);
// }
// }
According to the comments on the associated bug a lot of people have the same problem.
Did anyone find a workaround for the bug?
I also wanted to programmatically add some menu items to the main menu of an RCP application and was caught out by this bug.
Instead of using the WorkbenchMenuService.addContributionFactory(...) method I found you can add contibution items using the by extending the ExtensionContributionFactory class (which also has a createContributionItems() method), and then add this using the org.eclipse.ui.menus extension point as a new menuContribution.
I found this solution in this blog by Vogella.
Am very very new to Vaadin. Am setting up the project by looking into Github and other docs, where am using Spring-security, Vaadin, Maven.
I created sample vaadin-maven with spring security project. Now am getting login page then after suucessful login, am getting some MainView.java.
Am trying to change the upload .xls file and read that file and do some functionality and then download pop-up.
I have followed http://demo.vaadin.com/sampler/#ui/data-input/other/upload , but errors. unable to reproduce my output.
For now, am able to read the file using path " final String FILE_PATH = "F://input.xls";" But, i need option to upload the file and then use that file for further functionality.
After the functionality completed, i need to download the file.
Please suggest me how can i browse the file and upload and use the uploaded file for ding some read and write operation and then download Vaadin.
Am having sleepless nights for this. Please suggest me how can i come out of this.
Here is my code:
#Component
#Scope("prototype")
#VaadinView(RoleAdminView.NAME)
#Secured("ROLE_ADMIN")
public class RoleAdminView extends Panel implements View
{
public static final String NAME = "role_admin";
#PostConstruct
public void PostConstruct()
{
LoggerFactory.getLogger(this.getClass()).debug("POST");
setSizeFull();
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(true);
layout.setMargin(true);
layout.addComponent(new Button());
layout.addComponent(new Label("ROLE_ADMIN"));
layout.addComponent(new Link("Go back", new ExternalResource("#!" +
MainView.NAME)));
setContent(layout);
}
#Override
public void enter(ViewChangeListener.ViewChangeEvent event)
{
}
}
A big thank you in advance. Hope you guys sort out my issue :)
You can do,
public class RoleAdminView extends Panel implements View{
//add a button view
//
#Override
public void uploadFailed(Upload.FailedEvent event) {
Notification.show(event.getFilename() + "----" + event.getMIMEType());
//here it will show the error if upload failed
}
#Override
public void uploadSucceeded(SucceededEvent event) {
/// do your functionlity
}
#Override
public OutputStream receiveUpload(String filename, String mimeType) {
FileOutputStream fos = null;
// do your functionality to save in any path or server path
return fos; // Return the output stream to write to
}
}
I hope this my help you :)