How to get all the parents of the treeitem? - java

I am programming in GWT
i have tree which is like
1.A Folder
1.Marketing Folder
2.Sales Folder
1.In Folder
1.Invoice.txt
2. Out Folder
2.B folder
1. xyz
1.fgh
2. abc
3.C foder
If i click on Invoice.txt the output should be like
"A folder/Sales FOlder/In FOlder/Invoice.txt"
i am using getParent method to display th output but it is show me only the
"In folder".
Plese some one help me to understand this,
How wil i get the complete path.
I am using tree Widget

private String getPath(TreeItem selectedItem) {
StringBuilder builder = new StringBuilder();
buildPath(selectedItem, builder);
return builder.toString();
}
private void buildPath(TreeItem item, StringBuilder builder) {
if (item.getParentItem() != null) {
buildPath(item.getParentItem(), builder); //build path
builder.append('/');
}
builder.append(item.getText());
}

Related

ContextUpdateHandler interface does not work for a specific context

I tried to catch a specific context/named graph by implementing following function of the ContextUpdateHandler interface:
#Override
public Resource[] getUpdateContexts() {
getLogger().info("getUpdateContexts");
Resource[] res = new Resource[2];
res[0] = () -> "";
res[1] = () -> "http://example.com/testGraph";
return res;
}
When I make an insert or delete to the default graph, it works perfectly and it gets me into the handleContextUpdate() method where I can further process the update request. However, when I do any insert or delete on a specific context, say http://example.com/testGraph, it does not get recognized. Do you know what might be the problem?
I also tried to write it like this: <http://example.com/testGraph> and it didnt work
These are my queries:
# Does not work.
delete data {
graph <http://example.com/testGraph> {
<http://example.com/s/deleteThis2>
<http://example.com/p/deleteThis2>
<http://example.com/o/deleteThis2> }
}
# Works perfectly fine.
delete data {
<http://example.com/s/deleteThis2>
<http://example.com/p/deleteThis2>
<http://example.com/o/deleteThis2>
}
Thanks!
Did you try res[1] = new SimpleIRI("http://example.com/testGraph");?
Or check the backend code for route differentials
And try adding / to path

I need to display list of files generated using a method in java class into my tml file in Tapestry

I have a java class in which I have the method- getFiles() that prints a list of files in a directory. Here is the code
#Property
private String[] filesInDir;
public void getFiles(String path){
File aDirectory = new File("C://Users/A634682/report1/src/main/java/com/example/report1/reports2");
// get a listing of all files in the directory
filesInDir = aDirectory.list();
// sort the list of files (optional)
// Arrays.sort(filesInDir);
System.out.println("File list begins here >>>>>");
// have everything i need, just print it now
for ( int i=0; i<filesInDir.length; i++ )
{
System.out.println( "file: " + filesInDir[i] );
}
}
In the respective tml file, I want to print this string array containing file names in form of table on the webpage.
Any help in how I can proceed?
You can use a simple t:Loop component with your filesInDir as a source. One example can be found here: http://jumpstart.doublenegative.com.au/jumpstart/examples/tables/loop
You'd need to initialise the property before rendering starts, i.e. in setupRender().

How to search file inside a specific folder in google API v3

As i am using v3 of google api,So instead of using parent and chidren list i have to use fileList, So now i want to search list of file inside a specific folder.
So someone can suggest me what to do?
Here is the code i am using to search the file :
private String searchFile(String mimeType,String fileName) throws IOException{
Drive driveService = getDriveService();
String fileId = null;
String pageToken = null;
do {
FileList result = driveService.files().list()
.setQ(mimeType)
.setSpaces("drive")
.setFields("nextPageToken, files(id, name)")
.setPageToken(pageToken)
.execute();
for(File f: result.getFiles()) {
System.out.printf("Found file: %s (%s)\n",
f.getName(), f.getId());
if(f.getName().equals(fileName)){
//fileFlag++;
fileId = f.getId();
}
}
pageToken = result.getNextPageToken();
} while (pageToken != null);
return fileId;
}
But in this method it giving me all the files that are generated which i don't want.I want to create a FileList which will give file inside a specific folder.
It is now possible to do it with the term parents in q parameter in drives:list. For example, if you want to find all spreadsheets in a folder with id folder_id you can do so using the following q parameter (I am using python in my example):
q="mimeType='application/vnd.google-apps.spreadsheet' and parents in '{}'".format(folder_id)
Remember that you should find out the id of the folder files inside of which you are looking for. You can do this using the same drives:list.
More information on drives:list method can be seen here, and you can read more about other terms you can put to q parameter here.
To search in a specific directory you have to specify the following:
q : name = '2021' and mimeType = 'application/vnd.google-apps.folder' and '1fJ9TFZOe8G9PUMfC2Ts06sRnEPJQo7zG' in parents
This examples search a folder called "2021" into folder with 1fJ9TFZOe8G9PUMfC2Ts06sRnEPJQo7zG
In my case, I'm writing a code in c++ and the request url would be:
string url = "https://www.googleapis.com/drive/v3/files?q=name+%3d+%272021%27+and+mimeType+%3d+%27application/vnd.google-apps.folder%27+and+trashed+%3d+false+and+%271fJ9TFZOe8G9PUMfC2Ts06sRnEPJQo7zG%27+in+parents";
Searching files by folder name is not yet supported. It's been requested in this google forum but so far, nothing yet. However, try to look for other alternative search filters available in Search for Files.
Be creative. For example make sure the files within a certain folder contains a unique keyword which you can then query using
fullText contains 'my_unique_keyword'
You can use this method to search the files from google drive:
Files.List request = this.driveService.files().list();
noOfRecords = 100;
request.setPageSize(noOfRecords);
request.setPageToken(nextPageToken);
String searchQuery = "(name contains 'Hello')";
if (StringUtils.isNotBlank(searchQuery)) {
request.setQ(searchQuery);
}
request.execute();

View.getView() returns null

I'm trying to find my folder or view in my database. Which named Team Documents this folder has some filter option like By Date, By Category. But this returns me a null even the folder already exists.
String dbServer = "d23dbm95/23/A/IBM", dbFileName = "dbom\\farizan\\stsklb1.nsf";
public void runNotes()
{
Session session = null;
Database db = null;
View view = null;
Document doc = null;
try
{
NotesThread.sinitThread();
session = NotesFactory.createSession();
System.out.println("User = " + session.getUserName());
db = session.getDatabase(dbServer, dbFileName);
if(db.isOpen())
{
System.out.println("Title "+db.getTitle());
view = db.getView("Team Documents \\ By Date");
if(view == null)
{
System.out.println("still null");
}
}
}
catch(NotesException e)
{
e.printStackTrace();
}
}
I tried also to fill my getView() method like Team Documents. But still returns a null. Any approach to this problem?
While it would have been more helpful if you had included a link to a screenshot of your Domino Designer client's folder list, my best guess is that you have two folders, not one folder with "filter options". Also, my guess is that "Team Documents" is not actually a folder; it's just a prefix on the folder names that makes them appear to be nested in a parent folder.
If that's the case, you would need
iew = db.getView("Team Documents\\By Category");
Or
iew = db.getView("Team Documents\\By Date");
Note: No spaces before & after the backslashes.
If my assumptions above are not correct, then my suggestion would be to assign alias names to the folders in Domino Designer and use the aliases instead of the display names in your code. Frankly, that's always a good practice, because it allows your code to continue working even if you decide to change the display names.

Can strange paths cause a wrong structure of the file system?

Consider the following example:
//both files are the same
final File path = new File("/home/alice/../bob/file.txt");
final File canonicalPath = new File("/home/bob/file.txt");
File parent = canonicalPath;
while((parent = parent.getParentFile()) != null) {
System.out.println(parent.getName());
}
This would print:
bob
home
If I would use path instead of canonicalPath, would the output be the same or would it be:
bob
home
alice
home
This woule be very strange because it would suggest that alice is the parent of home which is not true.
First of all, I think you want to compare home/alice/../bob/file.txt without a starting / instead of /home/alice/../bob/file.txt, otherwise you'd be comparing apples with oranges.
Actually it's more interesting to compare the difference using this code instead:
File parent;
parent = path;
while((parent = parent.getParentFile()) != null) {
System.out.println(parent);
}
parent = canonicalPath;
while((parent = parent.getParentFile()) != null) {
System.out.println(parent);
}
The parents of "home/alice/../bob/file.txt":
"home/alice/../bob"
"home/alice/.."
"home/alice"
"home"
null
In contrast, the parents of "home/bob/file.txt":
"home/bob"
"home"
null
The result would not be the same since those are two different filesystem paths.
But use Path instead:
final Path path = Paths.get("/home/bob/../alice/somefile");
final Path normalized = path.normalize(); // /home/alice/somefile
path.toAbsolutePath(); // get an absolute path
path.toRealPath(); // same, but follows symlinks
// etc etc

Categories