因此,我正在尝试使用 MOSS 2007 Web 服务 API 的 Java 实现将文档上传到共享点站点。我已经设法将文件上传到网站,我可以通过手动查看目标 URL 来确认。但是,当使用所有文档视图时,该文件是不可见的。我觉得这与我如何设置元数据有关,但我不确定。
这是我的代码供参考:
public static void main(String[] args) {
JCopy copy = new JCopy("http://somespsite", "user", "pass");
try {
File f = new File("c:/test.txt");
byte[] b = new byte[(int) f.length()];
FileInputStream fileInputStream = new FileInputStream(f);
fileInputStream.read(b);
List<String> dest = new ArrayList<String>();
dest.add("http://somespsite/Test Repository/Forms/test.txt");
List< FieldInformation > fields = new ArrayList<FieldInformation>();
FieldInformation field = new FieldInformation();
field.setType(FieldType.TEXT);
field.setDisplayName("Test2");
field.setInternalName("Test2");
field.setId(java.util.UUID.randomUUID().toString());
field.setValue(field.getValue());
copy.copyIntoItems(
"c:/test.txt",
dest,
fields,
b,
null);
}catch (Exception e) {
e.printStackTrace();
}
}
class JCopy {
public int copyIntoItems(
String sourceUrl,
List<String> destinations,
List<FieldInformation> fields,
byte[] stream,
List<CopyResult> results )
{
DestinationUrlCollection destinationUrls = new DestinationUrlCollection();
for(String s : destinations)
destinationUrls.addString(s);
FieldInformationCollection fieldsInput = new FieldInformationCollection();
for(FieldInformation f : fields)
fieldsInput.addFieldInformation(f);
Holder<Long> copyIntoItemsResult = new Holder<Long>(Long.valueOf(-1));
Holder<CopyResultCollection> resultsOutput = new Holder<CopyResultCollection>((CopyResultCollection) results);
try {
port.copyIntoItems(sourceUrl, destinationUrls, fieldsInput, stream, copyIntoItemsResult, resultsOutput);
results = resultsOutput.value.getCopyResult();
} catch (Exception e) {
e.printStackTrace();
}
return copyIntoItemsResult.value.intValue();
}}
port 是 Netbeans 使用 JDK 1.6 生成的存根的一个实例。