How-to get the code for downloading metadata along with images in IBM content manager - ecm

I am trying to find the code in java API which works with cm IBM.. the sample code is there but it is just for logging in.. can anyone help to get the code to download the images along with metadata

as you said you have basic connection code, use the below function to download the document..
public String retrieveDocument(CMBConnection connection, CMBItem item)
throws CMBException, IOException, Exception
{
// Get an instance of data management bean
CMBDataManagement dataManagement = connection.getDataManagement();
// Set the current data item
dataManagement.setDataObject(item);
// Retrieve the original file name
CMBObject object = dataManagement.getContent(0);
String inputFileName = object.getOriginalFileName();
// Parse the file name from the full path
int pos=inputFileName.lastIndexOf("\\");
inputFileName = inputFileName.substring(pos+1);
// Write the document content to a new file
String fileName = System.getProperty("user.dir")
+ File.separator + inputFileName;
System.out.println("Output file name " + fileName);
FileOutputStream fileoutstream = new FileOutputStream(fileName);
fileoutstream.write(dataManagement.getContent(0).getData());
fileoutstream.close();
// Return file name
return fileName;
}

Related

MalformedInputException: Input length = 1 while reading text file with Files.readAllLines(Path.get("file").get(0);

Why am I getting this error? I'm trying to extract information from a bank statement PDF and tally different bills for the month. I write the data from a PDF to a text file so I can get specific data from the file (e.g. ASPEN HOME IMPRO, then iterate down to what the dollar amount is, then read that text line to a string)
When the Files.readAllLines(Path.get("bankData").get(0) code is run, I get the error. Any thoughts why? Encoding issue?
Here is the code:
public static void main(String[] args) throws IOException {
File file = new File("C:\\Users\\wmsai\\Desktop\\BankStatement.pdf");
PDFTextStripper stripper = new PDFTextStripper();
BufferedWriter bw = new BufferedWriter(new FileWriter("bankData"));
BufferedReader br = new BufferedReader(new FileReader("bankData"));
String pdfText = stripper.getText(Loader.loadPDF(file)).toUpperCase();
bw.write(pdfText);
bw.flush();
bw.close();
LineNumberReader lineNum = new LineNumberReader(new FileReader("bankData"));
String aspenHomeImpro = "PAYMENT: ACH: ASPEN HOME IMPRO";
String line;
while ((line = lineNum.readLine()) != null) {
if (line.contains(aspenHomeImpro)) {
int lineNumber = lineNum.getLineNumber();
int newLineNumber = lineNumber + 4;
String aspenData = Files.readAllLines(Paths.get("bankData")).get(0); //This is the code with the error
System.out.println(newLineNumber);
break;
} else if (!line.contains(aspenHomeImpro)) {
continue;
}
}
}
So I figured it out. I had to check the properties of the text file in question (I'm using Eclipse) to figure out what the actual encoding of the text file was.
Then, when creating the file in the program, encode the text file to UTF-8 so that Files.readAllLines could read and grab the data I wanted to get.

Why is my SQLite Database not created/saved to disk?

I created code to create a SQLite database based on the article here.
The most pertinent code is:
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "Platypus.db";
private static final String TABLE_VENDORS = "vendors";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_VENDORID = "vendorId";
public static final String COLUMN_COMPANYNAME = "companyName";
public SQLiteHandlerVendors(Context context, String vendor,
SQLiteDatabase.CursorFactory factory, int company) {
super(context, DATABASE_NAME, factory, DATABASE_VERSION);
}
#Override
public void onCreate(SQLiteDatabase db) {
String CREATE_VENDORS_TABLE = "CREATE TABLE " +
TABLE_VENDORS + "("
+ COLUMN_ID + " INTEGER PRIMARY KEY," + COLUMN_VENDORID
+ " TEXT," + COLUMN_COMPANYNAME + " TEXT" + ")";
db.execSQL(CREATE_VENDORS_TABLE);
}
public void addVendor(Vendor vendor) {
ContentValues values = new ContentValues();
values.put(COLUMN_VENDORID, vendor.getVendorId());
values.put(COLUMN_COMPANYNAME, vendor.getCompanyName());
SQLiteDatabase db = this.getWritableDatabase();
db.insert(TABLE_VENDORS, null, values);
db.close();
}
Yet, although the insertions of data seem to be working -- the calls to addVendor() run without any exception being thrown with the following code:
protected void onPostExecute(String result) {
try {
JSONArray jsonArr = new JSONArray(result);
for (int i = 0; i < jsonArr.length(); i++) {
JSONObject jsonObj = jsonArr.getJSONObject(i);
String vendorId = jsonObj.getString("vendorId");
String companyName = jsonObj.getString("companyName");
Log.i("vendorId", vendorId);
Log.i("companyName", companyName);
// Prepare for writing to db
Vendor vend = new Vendor();
vend.setVendorId(vendorId);
vend.setCompanyName(companyName);
SQLiteHandlerVendors sqliteHandler = new SQLiteHandlerVendors(MainActivity.this, null, null, 1);
sqliteHandler.addVendor(vend);
}
} catch (JSONException j) {
System.out.println(j.getMessage());
Log.i("jsonEx", j.getMessage());
}
Log.i("GetVendorsTask.FromOnPostExecute", result);
}
I cannot locate the Platypus.db file that should have been created.
This article says, "If your application creates a database, this database is by default saved in the directory DATA/data/APP_NAME/databases/FILENAME."
A global search for "Platypus.DB" on my hard drive turns up nothing. Is the database created not being persisted, or is there some other reason why I'm not finding it?
I tried to find it by adding this code:
Log.i("Data Dir", Environment.getDataDirectory().toString());
...and when LogCat gives me is:
04-07 12:36:47.133 1089-1089/platypus.app I/Data Dirīš• /data
There is no "data" folder in C:\Users\clay\AndroidStudioProjects\Platypus, nor is there one in the root of my hard drive (*C:*).
Can the data dir/file only be viewed in some virtual space, in a file system for the emulator or so? If so, how can I actually access the emulator's file system to view this data?
UPDATE
Okay, I opened up this view, and navigated to data/data/hhs (the app's name is really "hhs" not "platypus"):
...but still do not see HHS.DB (I see no "databases" folder below all that)...
UPDATE 2
If I select the "<=" button ("Pull a file from the device") with the file with the size of 16384 highlighted, it does open the "Get Device File" dialog with a filename of "HHS.DB" (just what I was hoping to find).
But, why is its path "data\data\hhs\unnamed folder\unnamed file" instead of "data\data\hhs\databases\HHS.DB"?
The other file (size 8720) is HHS.db-journal
UPDATE 3
After saving those files to my hard drive and downloading SQLite Data Browser, I'm able to verify that the records actually were written to the table:
SQLite Data Browser is a great tool for just such a need!
UPDATE 4
I don't know what changed/how it changed, but it's now working as it should:
There is no "data" folder in
C:\Users\clay\AndroidStudioProjects\Platypus, nor is there one in the
root of my hard drive (C:).
Yes that is corect.
Can the data dir/file only be viewed in some virtual space, in a file
system for the emulator or so? If so, how can I actually access the
emulator's file system to view this data?
Using Eclipse you can pull the db from your emulator
Goto windows open perspective. Goto DDMS
Then goto file explorer-> data->data->see your package name-> databases->Platypus.DB"
/data/data/[packagename]/databases/
You select the db and there is a option to pull the db and then you can use a sqlite browser to view the data

Saving images into a folder in android?

Hello am using camera in my application.So i want to save Captured images into folder in gallery,floder name must be application name?please suggest me with some Example?
Thanks in advance
You can create any folder or file you want. Read this Android article Taking Photos Simply:
Add the Photo to a Gallery When you create a photo through an intent,
you should know where your image is located, because you said where to
save it in the first place. For everyone else, perhaps the easiest way
to make your photo accessible is to make it accessible from the
system's Media Provider.
The following example method demonstrates how to invoke the system's
media scanner to add your photo to the Media Provider's database,
making it available in the Android Gallery application and to other
apps.
private void galleryAddPic() {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(mCurrentPhotoPath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
}
Use below code and modify the path where you want to save your image.
mImageView.setDrawingCacheEnabled(true); Bitmap bitmap =
mImageView.getDrawingCache();
String root = Environment.getExternalStorageDirectory().toString();
File newDir = new File(root + "/app_name/saved_images"); newDir.mkdirs();
Random gen = new Random(); int n = 10000; n = gen.nextInt(n); String
fotoname = "photo-" + n + ".jpg"; File file = new File(newDir,
fotoname); String s = file.getAbsolutePath();
System.err.print("******************" + s); if (file.exists())
file.delete(); try { FileOutputStream out = new
FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG,
90, out); out.flush(); out.close();
Toast.makeText(getApplicationContext(), "Saved to your folder ",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
}

Create doc file from template and adding data from database using open xml

I have a word template and I want to create doc file from that, also I want to replace add data in place of bookmarks present in the template.
I have been able to create a doc file, but I am not able to understand, how to add data in place of bookmarks?
My code till now:
private void CreateSampleWordDocument()
{
string sourceFile = Path.Combine(Environment.CurrentDirectory, "GeneralWelcomeLetter.dotx");
string destinationFile = Path.Combine(Environment.CurrentDirectory, "Sample.docx");
try
{
File.Copy(sourceFile, destinationFile, true);
WordprocessingDocument document = WordprocessingDocument.Open(destinationFile, true);
document.ChangeDocumentType(DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
MainDocumentPart mainPart = document.MainDocumentPart;
DocumentSettingsPart documentSettingPart1 = mainPart.DocumentSettingsPart;
AttachedTemplate attachedTemplate1 = new AttachedTemplate() { Id = "relationId1" };
documentSettingPart1.Settings.Append(attachedTemplate1);
}
catch
{
}
}
Now to add data from database in place of bookmarks?

google cloud storage failed to read file

Using the example from google, this is the way I am trying to read my file:
boolean lockForRead = false;
String filename = "/gs/my_bucket/my_object";
AppEngineFile readableFile = new AppEngineFile(filename);
FileReadChannel readChannel = fileService.openReadChannel(readableFile, lockForRead);
// Read the file in whichever way you'd like
BufferedReader reader = new BufferedReader(Channels.newReader(readChannel, "UTF8"));
String line = reader.readLine();
resp.getWriter().println("READ:" + line);
readChannel.close();
However, the code seams fine up to the reader.readLine line, where it throws an exception:
java.io.IOException
at com.google.appengine.api.files.FileServiceImpl.translateException(FileServiceImpl.java:615)
....
Caused by: com.google.apphosting.api.ApiProxy$ApplicationException: ApplicationError: 7: ...\war\WEB-INF\appengine-generated\encoded_gs_key:L2dzL21hcGxlL3NhdmUudHh0 (The system cannot find the file specified)
Help!