Setting content (Java parser)
Hi, I'm using a Java parser to take in binary files.
In windows explorer if I drag and drop on to an ifs
it works fine, however if the file already exists
then it is replaced by a 0 byte file of the same name.
Heres the relevant parser code:
public LibraryObject parse(InputStream inStream, ParserCallback callback, Hashtable options)
dis = new DataInputStream(inStream);
baos = new ByteArrayOutputStream();
int b = -99;
byte[] buffer = new byte[1024];
try
while((b = dis.read(buffer)) != -1)
if(b < buffer.length)
baos.write(buffer, 0, b);
else
baos.write(buffer);
catch(EOFException e)
DocumentDefinition docDef = new DocumentDefinition (m_librarySession);
Collection allFormats = m_librarySession.getFormatExtensionCollection();
docDef.setFormat((Format) allFormats.getItems("bin"));
docDef.setClassname("BINARYFILE");
docDef.setAttribute("NAME", AttributeValue.newAttributeValue(options.get(CURRENT_NAME_OPTION)));
byte[] outbytes = baos.toByteArray();
bais = new ByteArrayInputStream(outbytes);
docDef.setContentStream(bais);
Document newDoc = (Document)
m_librarySession.createPublicObject(docDef);
if(options.get(UPDATE_OBJECT_OPTION) != null)
Document currentDoc = (Document) currentFolder.findPublicObjectByPath
(docDef.getAttribute("NAME").toString());
currentDoc.update(docDef);
else
currentFolder.addItem(newDoc);
baos.close();
//bais.close();
//dis.close();
As I said this only causes trouble if the file is already present in the ifs directory I'm placing it in.
Thanks for your time,
Cathal
try moving this line:
m_librarySession.createPublicObject(docDef);
into the "else" block of your condition:
else
// move the line here
currentFolder.addItem(newDoc);
the mistake you're making is that you always create a new document, whether or not you want to update an existing document or not.
this mistake causes two problems:
1. when you're updating (i.e. the "if" block of your condition will execute) you leave the new document you created floating around.
2. when you're updating, the existing document content gets set to 0 bytes. why? because you already sucked out all the bytes from your bais when you created the new document earlier! when you try to update the existing one later, the bais is already "at the end" and there's nothing left to read out. for more info about this you should read up on the java.io package.
Similar Messages
-
How to set a different parser for JAXB ?
from the FAQ https://jaxb.dev.java.net/faq/index.html
A question about which jars are required says
"The runtime also needs a JAXP-compliant parser. If your target environment is
JRE 1.4 or higher , it is a part of JRE, so you don't need any more jar file.
Otherwise you have to bundle a parser, too. Any parser would do the job, but we
recommend the JAXP RI bundled in the JWSDP (which is what we test against.) "
I am running jdk1.3 and want to use a different parser how do I specify it.
Thanks
SteveI think I worked it out.
I just have to set the JAXP parser
Q. How do I use a different JAXP compatible implementation?
The JAXP 1.1 API allows applications to plug in different JAXP compatible implementations of parsers or XSLT processors. For example, when an application wants to create a new JAXP DocumentBuilderFactory instance, it calls the staic method DocumentBuilderFactory.newInstance(). This causes a search for the name of a concrete subclass of DocumentBuilderFactory using the following order:
1. The value of a system property like javax.xml.parsers.DocumentBuilderFactory if it exists and is accessible.
2. The contents of the file $JAVA_HOME/jre/lib/jaxp.properties if it exists.
3. The Jar Service Provider discovery mechanism specified in the Jar File Specification. A jar file can have a resource (i.e. an embedded file) such as META-INF/services/javax.xml.parsers.DocumentBuilderFactory containing the name of the concrete class to instantiate.
4. The fallback platform default implementation. -
Revision: 3127
Author: [email protected]
Date: 2008-09-05 14:16:53 -0700 (Fri, 05 Sep 2008)
Log Message:
Updating asdoc to replace the avmplus call with new set of java files.
Removing all files related to asdochelper.
QA: Yes, also please test on non windows platform.
Doc:
Tests: checkintests, asdoc
Reviewed by: Pete Farland
Modified Paths:
flex/sdk/trunk/asdoc/templates/ASDoc_Config_Base.xml
flex/sdk/trunk/asdoc/templates/asdoc-util.xslt
flex/sdk/trunk/modules/compiler/build.xml
flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/asdoc/AsDocAPI.java
Added Paths:
flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/asdoc/AsClass.java
flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/asdoc/AsDocHelper.java
flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/asdoc/AsDocUtil.java
flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/asdoc/QualifiedNameInfo.java
flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/asdoc/SortComparator.java
flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/asdoc/TopLevelClassesGenerator.ja va
Removed Paths:
flex/sdk/trunk/asdoc/templates/asDocHelper
flex/sdk/trunk/asdoc/templates/asDocHelper.linux
flex/sdk/trunk/modules/compiler/asdoc/I had a generic record class that has a HashMap to hold the data fields (...)
method called createRecord() for each record type which would populate the HashMap with the correct data fieldsI'm not sure I understand: are the contents of this field map the same between two records of the same type? Then yes, you don't need to clone the map per record instance.
one thing that needs fixing is the fact that each time the createRecord() method is called I'm creating a new fieldMap to define the dataFields in the record class.Probably, but that will only get you a little bigger files; you won't gain an order of magnitude on the size of files. The problem for huge files is that as soon as their content is bigger than the available memory, you'll run into problems. A more radical approach if you need to address huge files is to process the records on the fly, and not load all records in memory. Of course not all algorithms or business logic can afford that...
I know I could rewrite the code and create a class for each record type and declare the fieldMap static but I was wondering if anyone had any better suggestions The Record instance could receive and keep a reference to its RecordType instance, and ask the RecordType instance the DataType for a field's name. That way the RecordType encapsulates the map, and there's less risk that a clumsy other class modifies the static map.
before I go rewriting a load of code.A load of code?!? Even with the idea of the static map, you only have to edit the enum type (well more accurately, each RecordType enumerated constant's createRecord() method). -
How to set content type while sending an email?
Hello,
I want to set content type text/html while send an email using org.apache.commons.httpclient api. I am using MultipartPostMethod method. and i am set using object of multipartpostmethod like post.
and post.setRequestHeader("Content-Type","text/html").
but it wont work.
so please give me a proper solution.
example::
MultipartPostMethod post = new MultipartPostMethod("url");
post.addParameter("msgbody","html message");
post.setRequestHeader("Content-Type","text/html");
Regards,
Bhavesh KharwaActually, I'm writing a "HashMap" from servlet to applet. I have used your suggested content type "application/octet-stream" and another "appication/x-java-serialized-object" to try it. But in applet side, when I use (HashMap)in.readObject(), it always gives me a exception as:"java.util.HashMap; IllegalAccessException". Why?
Thankd. -
Hi,
I'm working on a Web Service Project, and i'm trying to deploy Web Services dynamically. Now the problem is, that i have to adapt the Java src-files sometimes before the deployment (Like adding Annotations, Methods or just peaces of code into a Method. So what i'm looking for is some Sort of a Java Parser, that gives me information on where to insert the code i generated.
Simple example:
public class WSExample{
public void doSomething(){
//do something
//this class should be changed to something like this:
public class WSExample{
@WebMethod //Annotation added
public void doSomething(){
//do something
//this Method is generated automatically
@WebMethod
public void doSomethingDifferent{
//like establishing a connection to a different WS
}All i've found up to now are parser generators like antlr or javacc. But i couldn't find anything about how to use the generated parsers or even manipulate the parsed code, yet. I hope i don't have to write a parser or grammar myself. Maybe someone can link me to some useful tutorial, forum or whatever else might be helpful.If you are using Sun's Java 1.4, you already have one. If you are using an ealier version, here are a couple of links:
Xerces is probably the most feature rich:
http://xml.apache.org/xerces2-j/index.html
GNU JAXP is also good and very small:
http://www.gnu.org/software/classpathx/jaxp/ -
Workflow Error Message: System Account - The Workflow could not set Content Approval Status
This is the first time I try an approval workflow. I am using a template in MS Word and assigned an approval workflow to it. The approval workflow is only going to one person in this case.
When I start the work flow the following 3 error messages show up:
Workflow Error Message: System Account - The Workflow could not set Content Approval Status. Enable content moderation for this list and run the workflow again.
Workflow Error Message: System Account - The e-mail message cannot be sent. Make sure the e-mail has a valid recipient.
Workflow Error Message: System Account - The e-mail message cannot be sent. Make sure the outgoing e-mail settings for the server are configured correctly.
Thank you for your kind guidance.Hi,
For the first error: Did you set Content Approval in the workflow? If so, see if you have it in the versioning settings of the list settings.
For the second error: double check your recipient is set up as being valid. Did you type in the email address or is it referring to a people picker field? also, make sure that in the workflow for the email that you actually populated it in the
To: field.
for the third error: I suspect that either your farm is not configured for email. Or, this error is a knock on from the second error. If you get the second error rectified it may clear this error. If not then double check the email settings
for your farm.
Johnathan Lightfoot -
SP2010 Designer workflow "Set Content Approval Status" does not work
Hello
I'm having a problem with a workflow for one of my clients.It is a SharePoint 2010 environment and I can only use SharePoint 2010 designer (no visual studio).
We have an approval workflow in place, which works great. After the document approval workflow has does its thing, a new workflow can be launged by specific users (they have writing rights and can approve content). The workflow is used to set the release
date of the document. This can only be determined after content approval.
However, when the release date is set, the document approval status is changed to concept. This is of course to be expected, as we changed to document metadata. That is why I wanted to add the action "Set content approval" to this workflow. I cannot
seem to get this action to work. Right now the workflow does the following:
check out the document (check out is obligatory in our library)
set the release date field to the released date parameter (defined when starting the workflow)
check in the document
set content approval to approved.
The release date gets set to the parameter value, but the document is not checked in and the content approval status is not set. SharePoint produces the following error message (translated from Dutch): "An error occured. Cannot edit the item, possibly
because one or more columns require another type of content. Unknown error."
Guided by other posts online I gathered that this might be because the actions checkin and set content approval occur to close together. I tried letting the workflow pause for the duration of 1 minute after checking in, but this pauses the workflow indefinitely.
I then tried 5 minutes (as this is the time standard set by SP2010 designer) but this also resulted in indefinite pausing.
Posts online lead me to believe that I'm not the only suffering from this problem, but as of yet, I haven't been able to find a solution that works for me. Hopefully someone can help me.Hi,
According to your post, my understanding is that the "Set Content Approval Status" didn’t work in SharePoint 2010 Designer workflow.
I try to reproduce the issue and the result is the same as yours.
If I only check out and check in the item, the workflow works well.
However, once I set Content Approval Status after checking in the item, the workflow get error.
As a workaround, I recommend to use two workflow to achieve what you want.
First, create the first workflow, and allow the workflow to be manually started.
Then, create the second workflow, and
start the workflow automatically when an item is changed.
When you start the first workflow, the document will be set value of the release date. And then the second workflow will be started automatically to set the content approval status.
Thank you for your understanding.
Best Regards,
Linda Li
Linda Li
TechNet Community Support -
How to use the build-in Java parser
Hi All,
I want do use the build-in Java parser. Is this possible? For example I have the following code:
package ch.fhnw;
import javax.tools.*;
public class JavacExample {
* @param args
public static void main(String[] args) {
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
String arguments = "./src/ch/fhnw/JavacExample.java";
int rc = javac.run(null , null, null, "-verbose", arguments);
System.out.println("Return value: " + rc);
}After parsing, it would be great to have an object or similar which contains the methods, arguments used by the methods, etc. The target is to extract method declarations from java files. Is there a simple way to do it without defining my own EBNF like in JavaCC? Or any other way?
Thank you for your help.
kind regards,
wolfgangYep. bootstrap your knowledge here
[http://java.sun.com/javase/6/docs/technotes/guides/javac/index.html]
[http://forum.java.sun.com/forum.jspa?forumID=514]
Bruce -
Parameter set in Java stack for retention of messages in PI
Hi,
Can you tel me which paramter is set in Java stack for retention of messages in adapter engine and where we can we find in Java stack?
Thanks.RWB --> Component MOnitoring --> Adapter Engine --> Background Processing
http://help.sap.com/saphelp_nwpi71/helpdata/en/05/b1b740f83db533e10000000a155106/frameset.htm -
Fatal error in Java Parser V2 :Status??
We still have a problem with entity references
in V2 of the JAVA XML parser (see Rolf van Deuresen 24-11).
It is a very urgent problem for us. We think that the XML-team
is working on it. Can you inform me abouth the status with the
(bug??)-fix. If you need more information on the problem, please
ask.
Greetings,
Erik van den Berg.
nullAttachments: "1|type=text/plain|desc=SAXSample output|17142|file=output.txt|"
Oracle XML Team wrote:
: Erik van den Berg (guest) wrote:
: : Oracle XML Team wrote:
: : : Erik van den Berg (guest) wrote:
: : : : We still have a problem with entity references
: : : : in V2 of the JAVA XML parser (see Rolf van Deuresen 24-
11).
: : : : It is a very urgent problem for us. We think that the
XML-
: : team
: : : : is working on it. Can you inform me abouth the status
with
: : the
: : : : (bug??)-fix. If you need more information on the
problem,
: : : please
: : : : ask.
: : : : Greetings,
: : : : Erik van den Berg.
: : : Have you downloaded the latest version 2.0.2.5 that was
made
: : : available this week?
: : : Oracle XML Team
: : : http://technet.oracle.com
: : : Oracle Technology Network
: : I have downloaded the new version 2.0.2.5 of the Java
parser,
: : and it stil doesn't work. Please refer to the original
message
: : from Rolf van Deursen (24th november 1999) for the details.
: : Maybe it will help you if I mail you a XML file that fails.
If
: : so, please give me your email account.
: : Greetings,
: : Erik van den Berg.
: You can attach files to messages in the forum here.
: Oracle XML Team
: http://technet.oracle.com
: Oracle Technology Network
Here's the XML that raises the Fatal error. The following
information is generated by the parser:
Fatal Error of Java SAX parser v2.0.2.5:
XML-0121: (Fatal Error) End tag does not match start
tag 'WOONPLAATS'. at line 517, column 4151 of XML document.
I attached the output of the SAXSample class, so you can trace
the line and column where the error occurs. Also attached is the
XML file (4Mb).
An other error that occurs with this XML is the following
situation:
<VOLGNR_FILM> 001</VOLGNR_FILM>
this piece of XML is parsed with the following events:
StartElement:VOLGNR_FILM
Characters:NR_
Characters:001
EndElement:VOLGNR_FILM
So the spaces are replace with a part of the start tag! This is
also only with large files. I tested this piece of XML in a
seperate file. Then it was parsed correctly.
Kind regards,
Erik.
null -
Create a CF Query Result Set in Java
I'd like to programatically build a ColdFusion query resultset inside of a Java class and return it to the calling application. See the Java psudocode below to see what I'm talking about:
public class MyClass {
public coldfusion.sql.QueryTable getQuery() {
// Create a query table object
QueryTable myTable = ..?
// Loop through some set of instance data for my class
for(int c = 0; c < this.myWigets.length; c++) {
int row = c+1;
myTable.setField(row, nameCol, this.myWigets[c].name);
myTable.setField(row, colorCol, this.myWigets[c].color);
return myTable;
I've had stuff like this partially working in the past but had issues with things like query of queries and such probably due to the hacks used to create the QueryTable object. I'm mainly just checking in to see if there has been any progress made in this area. To me this seems like such an obvious thing for a Java developer working within CF to want to do. I'm surprised Adobe doesn't have an officially supported API for doing this sort of thing (or maybe I'm just too dumb to find it.) A few other notes... I'm not using CFX, and I'm not starting with a java.sql.ResultSet otherwise I would use the QueryTable(java.sql.ResultSet) constructor. I need to build this thing from scratch programatically.
Thanks for your time. I hope this question makes sense to someone out there.
- MikeI appologize. I wasn't very clear with my original question.
I'm creating an instance of my Java class from within CF using createObject("java", "com.example.MyClass"). So based on the sample code in my original post on the CF side I'd like to do something like this:
<cfscript>
myObj = createObject("java", "com.example.MyClass");
myObj.doSomeStuff();
myCFQuery = myObj.getQuery(); // Return a CF query from my java class
</cfscript>
... then do stuff like ...
<cfquery name="mySortedQuery" dbtype="query">
select *
from myCFQuery
order by color
</cfquery>
I appriciate your suggestions so far. I have other solutions working already but they are not ideal. I was just hoping someone had a clean and as-hack-free-as-possible way of creating a ColdFusion query result set in Java and passing it back to CF.
Thanks again,
Mike -
Set Content Copying: Not allowed in Adobe forms
We have developed an adobe form, non interactive form, which has scanned signatures, incorporated as images, of authorized personnel.
But we found that these signatures (images) can be copied by standard copy (Ctr+c).
After a brief study we could find out that we need to set the Content Copying as Not allowed, in document properties, as one of the possible solution, but we are unable to do so.
Could you please suggest a way out as to how do we set Content Copying: Not allowed, in the document properties, of the PDF document.Thank you for your view.
The XML equivalent of the Adobe form, designed, has a tag <PDF security> which has "copy content" set as 1. The possible solution to my problem is to set the copy content to zero or a value which deactivates the copy content. But even though we set the value to zero, the moment we activate the form it reset itself to 1. Could you please elaborate on this one? -
How to set Content Set from 'Parallel' to 'Sequential' in Report Manager?
Dear All,
How to set Content Set from 'Parallel' to 'Sequential' in Report Manager?
Thanks,
JackieSorry, Please ignore, thanks...
-
Setting Multiple values in property set using java API
Hello All,
I want to set the properties of a profile in a property set using java API provided
in package p13n. The property can have multiple values. When I try to add the
property using ProfileManager.setProperty() method. But every time I do it this
way, it replaces the earlier value of property and not added. This, I can achieve
using portalTools but I want to use the API for user registration on the site.
I hope the query is clear.
Waiting for a response,
Thanks in advance,
ShrinivasYou need to use java.util.ArrayList.
First cast the existing value into ArrayList using getProperty method,
change values in the ArrayList and then put them back with setProperty
method.
Regards,
Michael Goldverg
"Shrinivas Rao" <[email protected]> wrote in message
news:3d64e7d9$[email protected]..
>
Hello All,
I want to set the properties of a profile in a property set using java APIprovided
in package p13n. The property can have multiple values. When I try to addthe
property using ProfileManager.setProperty() method. But every time I do itthis
way, it replaces the earlier value of property and not added. This, I canachieve
using portalTools but I want to use the API for user registration on thesite.
I hope the query is clear.
Waiting for a response,
Thanks in advance,
Shrinivas -
How can i build a java parser/interpreter
How can i build a java parser/interpreter
i know java offers a tokenizer, how can i use it for build a parser or interpreter that recognize tags like this:
<query db="db1" select="row1, row2">
and then perform some actionshow can i use it for build a parser or interpreter that recognize tags like this:A compiler design class would help understand the issues involved.
Or as suggested if you are merely trying to parse XML then there are variety of existing solutions.
Of if not XML and you already understand the principles of compiler design (formally or perhaps with experience with lexx/yacc) then you could use JavaCC
http://www.webgain.com/products/java_cc/
Maybe you are looking for
-
After loading OSX 10.9.2, my printer is no longer recognized by my Mac. I have a Canon MG 7120 and it is connected wirelessly.
-
Apple no longer allows RESTORE via 3.0.1?!
i have an event tomorrow. EARLY. i dont want to download the 3.1 ipsw tonight cuz my net connection is SLOW but i need to restore so i can get up and go to WORK in the morning with a _working phone_. i only need to restore because after downloading _
-
Web Service Client works from IDE, not standalone
I'm using the Netbeans 5.5 IDE & JAX-WS 2.0 & jdk1.6. I use an Applet to call a webservice on an embedded web-server which has gSoap generated WebServices. The code works fine if I run it from the IDE. However, the following error occurs if I run it
-
How to Install Apache 2.x with ssl on solaris 8/9 for reverse proxy
Hi, I need to install Apache 2.x on solaris , along with mod_ssl and openssl . I am not sure where to find the required version for solaris and also where to find openssl and mod_ssl for installation for 2.x. I need this for configuring reverse proxy
-
Some Questions about Sun Java Studio Creator IDE
I am quiet new to the IDE, but I experienced some behaviours I do not actually understand. I hope I can get some help here. Sun Java Studio Creator Update 9 Each time I change the font size and type using the "Advanced" option of the IDE the font I c