scripting: Format_java_code.sh initial run
Conflicts: scripting/java/com/sun/star/script/framework/io/UCBStreamHandler.java Change-Id: I09b94d8c96dfbaf498bd93a0088feb80a9e4afb6
This commit is contained in:
committed by
David Tardon
parent
36d24bced0
commit
6f42a71439
@@ -40,11 +40,11 @@ public class DeployedUnoPackagesDB {
|
||||
|
||||
public DeployedUnoPackagesDB() throws IOException {
|
||||
ByteArrayInputStream bis = null;
|
||||
|
||||
try {
|
||||
bis = new ByteArrayInputStream(EMPTY_DOCUMENT);
|
||||
this.document = XMLParserFactory.getParser().parse(bis);
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
if (bis != null)
|
||||
bis.close();
|
||||
}
|
||||
@@ -58,8 +58,7 @@ public class DeployedUnoPackagesDB {
|
||||
this(XMLParserFactory.getParser().parse(is));
|
||||
}
|
||||
|
||||
public String[] getDeployedPackages( String language )
|
||||
{
|
||||
public String[] getDeployedPackages(String language) {
|
||||
ArrayList<String> packageUrls = new ArrayList<String>(4);
|
||||
Element main = document.getDocumentElement();
|
||||
Element root = null;
|
||||
@@ -67,38 +66,36 @@ public class DeployedUnoPackagesDB {
|
||||
NodeList langNodes = null;
|
||||
|
||||
if ((langNodes = main.getElementsByTagName("language")) != null &&
|
||||
(len = langNodes.getLength()) != 0)
|
||||
{
|
||||
for ( int i=0; i<len; i++ )
|
||||
{
|
||||
Element e = (Element)langNodes.item( i );
|
||||
if ( e.getAttribute("value").equals(language) )
|
||||
{
|
||||
(len = langNodes.getLength()) != 0) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
Element e = (Element)langNodes.item(i);
|
||||
|
||||
if (e.getAttribute("value").equals(language)) {
|
||||
root = e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( root != null )
|
||||
{
|
||||
|
||||
if (root != null) {
|
||||
len = 0;
|
||||
NodeList packages = null;
|
||||
|
||||
if ((packages = root.getElementsByTagName("package")) != null &&
|
||||
(len = packages.getLength()) != 0)
|
||||
{
|
||||
(len = packages.getLength()) != 0) {
|
||||
|
||||
for ( int i=0; i<len; i++ )
|
||||
{
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
||||
Element e = (Element)packages.item( i );
|
||||
packageUrls.add( e.getAttribute("value") );
|
||||
Element e = (Element)packages.item(i);
|
||||
packageUrls.add(e.getAttribute("value"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !packageUrls.isEmpty() )
|
||||
{
|
||||
return packageUrls.toArray( new String[packageUrls.size()] );
|
||||
|
||||
if (!packageUrls.isEmpty()) {
|
||||
return packageUrls.toArray(new String[packageUrls.size()]);
|
||||
}
|
||||
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@@ -111,52 +108,49 @@ public class DeployedUnoPackagesDB {
|
||||
}
|
||||
|
||||
|
||||
public boolean removePackage( String language, String url )
|
||||
{
|
||||
public boolean removePackage(String language, String url) {
|
||||
Element main = document.getDocumentElement();
|
||||
Element langNode = null;
|
||||
int len = 0;
|
||||
NodeList langNodes = null;
|
||||
boolean result = false;
|
||||
|
||||
if ((langNodes = main.getElementsByTagName("language")) != null &&
|
||||
(len = langNodes.getLength()) != 0)
|
||||
{
|
||||
for ( int i=0; i<len; i++ )
|
||||
{
|
||||
Element e = (Element)langNodes.item( i );
|
||||
if ( e.getAttribute("value").equals(language) )
|
||||
{
|
||||
(len = langNodes.getLength()) != 0) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
Element e = (Element)langNodes.item(i);
|
||||
|
||||
if (e.getAttribute("value").equals(language)) {
|
||||
langNode = e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( langNode != null )
|
||||
{
|
||||
|
||||
if (langNode != null) {
|
||||
len = 0;
|
||||
NodeList packages = null;
|
||||
if ((packages = langNode.getElementsByTagName("package")) != null &&
|
||||
(len = packages.getLength()) != 0)
|
||||
{
|
||||
for ( int i=0; i<len; i++ )
|
||||
{
|
||||
|
||||
Element e = (Element)packages.item( i );
|
||||
if ((packages = langNode.getElementsByTagName("package")) != null &&
|
||||
(len = packages.getLength()) != 0) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
||||
Element e = (Element)packages.item(i);
|
||||
String value = e.getAttribute("value");
|
||||
|
||||
if ( value.equals(url) )
|
||||
{
|
||||
langNode.removeChild( e );
|
||||
if (value.equals(url)) {
|
||||
langNode.removeChild(e);
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void addPackage(String language, String url ) {
|
||||
public void addPackage(String language, String url) {
|
||||
Element main = document.getDocumentElement();
|
||||
Element langNode = null;
|
||||
Element pkgNode = null;
|
||||
@@ -165,25 +159,24 @@ public class DeployedUnoPackagesDB {
|
||||
NodeList langNodes = null;
|
||||
|
||||
if ((langNodes = document.getElementsByTagName("language")) != null &&
|
||||
(len = langNodes.getLength()) != 0)
|
||||
{
|
||||
for ( int i=0; i<len; i++ )
|
||||
{
|
||||
Element e = (Element)langNodes.item( i );
|
||||
if ( e.getAttribute("value").equals(language) )
|
||||
{
|
||||
(len = langNodes.getLength()) != 0) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
Element e = (Element)langNodes.item(i);
|
||||
|
||||
if (e.getAttribute("value").equals(language)) {
|
||||
langNode = e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( langNode == null )
|
||||
{
|
||||
|
||||
if (langNode == null) {
|
||||
langNode = document.createElement("language");
|
||||
langNode.setAttribute( "value", language );
|
||||
langNode.setAttribute("value", language);
|
||||
}
|
||||
|
||||
pkgNode = document.createElement("package");
|
||||
pkgNode.setAttribute( "value", url );
|
||||
pkgNode.setAttribute("value", url);
|
||||
|
||||
langNode.appendChild(pkgNode);
|
||||
//add to the Top Element
|
||||
|
@@ -28,20 +28,19 @@ import com.sun.star.ucb.XSimpleFileAccess2;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class Parcel implements XNameContainer
|
||||
{
|
||||
public class Parcel implements XNameContainer {
|
||||
private ParcelDescriptor m_descriptor;
|
||||
private String name;
|
||||
protected ParcelContainer parent;
|
||||
protected XSimpleFileAccess m_xSFA;
|
||||
public Parcel( XSimpleFileAccess xSFA, ParcelContainer parent, ParcelDescriptor desc, String parcelName )
|
||||
{
|
||||
this( parent, desc, parcelName );
|
||||
this.m_xSFA = xSFA;
|
||||
public Parcel(XSimpleFileAccess xSFA, ParcelContainer parent,
|
||||
ParcelDescriptor desc, String parcelName) {
|
||||
this(parent, desc, parcelName);
|
||||
this.m_xSFA = xSFA;
|
||||
}
|
||||
|
||||
private Parcel( ParcelContainer parent, ParcelDescriptor desc, String parcelName )
|
||||
{
|
||||
private Parcel(ParcelContainer parent, ParcelDescriptor desc,
|
||||
String parcelName) {
|
||||
this.parent = parent;
|
||||
this.m_descriptor = desc;
|
||||
this.name = parcelName;
|
||||
@@ -53,23 +52,24 @@ public class Parcel implements XNameContainer
|
||||
*
|
||||
* @return <tt>true</tt> if has parent <tt>false</tt> otherwise
|
||||
*/
|
||||
public boolean isUnoPkg() { return parent.isUnoPkg(); }
|
||||
public boolean isUnoPkg() {
|
||||
return parent.isUnoPkg();
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public java.lang.Object getByName( String aName ) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException
|
||||
{
|
||||
LogUtils.DEBUG("** Parcel.getByName for " + aName );
|
||||
public java.lang.Object getByName(String aName) throws
|
||||
com.sun.star.container.NoSuchElementException,
|
||||
com.sun.star.lang.WrappedTargetException {
|
||||
LogUtils.DEBUG("** Parcel.getByName for " + aName);
|
||||
ScriptEntry thescript = null;
|
||||
try
|
||||
{
|
||||
if ( m_descriptor != null && hasElements() )
|
||||
{
|
||||
|
||||
try {
|
||||
if (m_descriptor != null && hasElements()) {
|
||||
ScriptEntry[] scripts = m_descriptor.getScriptEntries();
|
||||
if ( scripts.length != 0 )
|
||||
{
|
||||
|
||||
if (scripts.length != 0) {
|
||||
for (ScriptEntry script : scripts) {
|
||||
if (script.getLanguageName().equals(aName)) {
|
||||
thescript = script;
|
||||
@@ -80,51 +80,50 @@ public class Parcel implements XNameContainer
|
||||
}
|
||||
}
|
||||
// catch unknown or un-checked exceptions
|
||||
catch ( Exception e )
|
||||
{
|
||||
catch (Exception e) {
|
||||
throw new com.sun.star.lang.WrappedTargetException(e);
|
||||
}
|
||||
if ( thescript == null )
|
||||
{
|
||||
LogUtils.DEBUG("No script for " + aName );
|
||||
throw new com.sun.star.container.NoSuchElementException("No script named " + aName );
|
||||
}
|
||||
ScriptMetaData data = new ScriptMetaData( this, thescript, null );
|
||||
|
||||
LogUtils.DEBUG("returning date for " + aName );
|
||||
if (thescript == null) {
|
||||
LogUtils.DEBUG("No script for " + aName);
|
||||
throw new com.sun.star.container.NoSuchElementException("No script named " +
|
||||
aName);
|
||||
}
|
||||
|
||||
ScriptMetaData data = new ScriptMetaData(this, thescript, null);
|
||||
|
||||
LogUtils.DEBUG("returning date for " + aName);
|
||||
return data;
|
||||
}
|
||||
public String[] getElementNames()
|
||||
{
|
||||
public String[] getElementNames() {
|
||||
String[] results = new String[0];
|
||||
if ( m_descriptor != null )
|
||||
{
|
||||
|
||||
if (m_descriptor != null) {
|
||||
ScriptEntry[] scripts = m_descriptor.getScriptEntries();
|
||||
results = new String[ scripts.length ];
|
||||
for ( int index = 0; index < scripts.length; index++ )
|
||||
{
|
||||
|
||||
for (int index = 0; index < scripts.length; index++) {
|
||||
results[ index ] = scripts[ index ].getLanguageName();
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
public boolean hasByName( String aName )
|
||||
{
|
||||
public boolean hasByName(String aName) {
|
||||
|
||||
boolean result = true;
|
||||
Object containee = null;
|
||||
try
|
||||
{
|
||||
containee = getByName( aName );
|
||||
if ( containee != null )
|
||||
{
|
||||
|
||||
try {
|
||||
containee = getByName(aName);
|
||||
|
||||
if (containee != null) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
} catch (Exception e) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -136,68 +135,64 @@ public class Parcel implements XNameContainer
|
||||
return new Type();
|
||||
}
|
||||
|
||||
public boolean hasElements()
|
||||
{
|
||||
public boolean hasElements() {
|
||||
return m_descriptor != null && m_descriptor.getScriptEntries().length > 0;
|
||||
}
|
||||
|
||||
public void replaceByName( String aName, java.lang.Object aElement ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException
|
||||
{
|
||||
// TODO check type of aElement
|
||||
// if not ok, throw IllegalArgument
|
||||
if ( m_descriptor != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
ScriptEntry script = (ScriptEntry)getByName( aName );
|
||||
if ( script != null )
|
||||
{
|
||||
//m_descriptor.removeScriptEntry( script );
|
||||
// TODO needs to create source file ( if there is one )
|
||||
//m_descriptor.write();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new com.sun.star.container.NoSuchElementException("No script named " + aName );
|
||||
}
|
||||
public void replaceByName(String aName,
|
||||
java.lang.Object aElement) throws com.sun.star.lang.IllegalArgumentException,
|
||||
com.sun.star.container.NoSuchElementException,
|
||||
com.sun.star.lang.WrappedTargetException {
|
||||
// TODO check type of aElement
|
||||
// if not ok, throw IllegalArgument
|
||||
if (m_descriptor != null) {
|
||||
try {
|
||||
ScriptEntry script = (ScriptEntry)getByName(aName);
|
||||
|
||||
if (script != null) {
|
||||
//m_descriptor.removeScriptEntry( script );
|
||||
// TODO needs to create source file ( if there is one )
|
||||
//m_descriptor.write();
|
||||
} else {
|
||||
throw new com.sun.star.container.NoSuchElementException("No script named " +
|
||||
aName);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// TO DO should catch specified exceptions
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new com.sun.star.lang.WrappedTargetException();
|
||||
}
|
||||
}
|
||||
// TO DO should catch specified exceptions
|
||||
catch (Exception e) {
|
||||
throw new com.sun.star.lang.WrappedTargetException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create
|
||||
public void insertByName( String aName, java.lang.Object aElement ) throws com.sun.star.lang.IllegalArgumentException, ElementExistException, com.sun.star.lang.WrappedTargetException
|
||||
{
|
||||
public void insertByName(String aName,
|
||||
java.lang.Object aElement) throws com.sun.star.lang.IllegalArgumentException,
|
||||
ElementExistException, com.sun.star.lang.WrappedTargetException {
|
||||
// TODO check the type of aElement and throw#
|
||||
// if not appropriate
|
||||
try
|
||||
{
|
||||
if ( hasByName( aName ) )
|
||||
{
|
||||
throw new ElementExistException( aName );
|
||||
try {
|
||||
if (hasByName(aName)) {
|
||||
throw new ElementExistException(aName);
|
||||
}
|
||||
|
||||
ScriptMetaData script = (ScriptMetaData)aElement;
|
||||
|
||||
if ( script.hasSource() )
|
||||
{
|
||||
if (script.hasSource()) {
|
||||
LogUtils.DEBUG("Inserting source: " + script.getSource());
|
||||
if ( !script.writeSourceFile() )
|
||||
{
|
||||
throw new com.sun.star.lang.WrappedTargetException( "Failed to create source file " + script.getLanguageName() );
|
||||
|
||||
if (!script.writeSourceFile()) {
|
||||
throw new com.sun.star.lang.WrappedTargetException("Failed to create source file "
|
||||
+ script.getLanguageName());
|
||||
}
|
||||
}
|
||||
m_descriptor.addScriptEntry( script );
|
||||
|
||||
m_descriptor.addScriptEntry(script);
|
||||
writeParcelDescriptor();
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
} catch (Exception e) {
|
||||
LogUtils.DEBUG("Failed to insert entry " + aName + ": " + e.getMessage());
|
||||
throw new com.sun.star.lang.WrappedTargetException(e);
|
||||
}
|
||||
@@ -205,82 +200,80 @@ public class Parcel implements XNameContainer
|
||||
|
||||
|
||||
private void writeParcelDescriptor()
|
||||
throws com.sun.star.ucb.CommandAbortedException,
|
||||
com.sun.star.io.IOException,
|
||||
com.sun.star.uno.Exception, java.io.IOException
|
||||
{
|
||||
throws com.sun.star.ucb.CommandAbortedException,
|
||||
com.sun.star.io.IOException,
|
||||
com.sun.star.uno.Exception, java.io.IOException {
|
||||
String pathToDescriptor = PathUtils.make_url(
|
||||
getPathToParcel(), ParcelDescriptor.PARCEL_DESCRIPTOR_NAME );
|
||||
getPathToParcel(), ParcelDescriptor.PARCEL_DESCRIPTOR_NAME);
|
||||
|
||||
XSimpleFileAccess2 xSFA2 = UnoRuntime.queryInterface( XSimpleFileAccess2.class, m_xSFA );
|
||||
XSimpleFileAccess2 xSFA2 = UnoRuntime.queryInterface(XSimpleFileAccess2.class,
|
||||
m_xSFA);
|
||||
|
||||
if ( xSFA2 != null )
|
||||
{
|
||||
if (xSFA2 != null) {
|
||||
ByteArrayOutputStream bos = null;
|
||||
ByteArrayInputStream bis = null;
|
||||
XInputStreamImpl xis = null;
|
||||
try
|
||||
{
|
||||
bos = new ByteArrayOutputStream( 1024 );
|
||||
m_descriptor.write( bos );
|
||||
bis = new ByteArrayInputStream( bos.toByteArray() );
|
||||
|
||||
xis = new XInputStreamImpl( bis );
|
||||
xSFA2.writeFile( pathToDescriptor, xis );
|
||||
}
|
||||
finally
|
||||
{
|
||||
try {
|
||||
bos = new ByteArrayOutputStream(1024);
|
||||
m_descriptor.write(bos);
|
||||
bis = new ByteArrayInputStream(bos.toByteArray());
|
||||
|
||||
xis = new XInputStreamImpl(bis);
|
||||
xSFA2.writeFile(pathToDescriptor, xis);
|
||||
} finally {
|
||||
if (bos != null) bos.close();
|
||||
|
||||
if (bis != null) bis.close();
|
||||
|
||||
if (xis != null) xis.closeInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// delete
|
||||
public void removeByName( String Name ) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException
|
||||
{
|
||||
try
|
||||
{
|
||||
ScriptMetaData script = (ScriptMetaData)getByName( Name );
|
||||
if ( script != null )
|
||||
{
|
||||
if ( !script.removeSourceFile() )
|
||||
{
|
||||
public void removeByName(String Name) throws
|
||||
com.sun.star.container.NoSuchElementException,
|
||||
com.sun.star.lang.WrappedTargetException {
|
||||
try {
|
||||
ScriptMetaData script = (ScriptMetaData)getByName(Name);
|
||||
|
||||
if (script != null) {
|
||||
if (!script.removeSourceFile()) {
|
||||
LogUtils.DEBUG("** Parcel.removeByName Failed to remove script " + Name);
|
||||
throw new com.sun.star.lang.WrappedTargetException("Failed to remove script " + Name);
|
||||
throw new com.sun.star.lang.WrappedTargetException("Failed to remove script " +
|
||||
Name);
|
||||
}
|
||||
LogUtils.DEBUG("** Parcel.removeByName have removed script source file " + Name);
|
||||
m_descriptor.removeScriptEntry( script );
|
||||
|
||||
LogUtils.DEBUG("** Parcel.removeByName have removed script source file " +
|
||||
Name);
|
||||
m_descriptor.removeScriptEntry(script);
|
||||
writeParcelDescriptor();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new com.sun.star.container.NoSuchElementException( "No script named " + Name );
|
||||
} else {
|
||||
throw new com.sun.star.container.NoSuchElementException("No script named " +
|
||||
Name);
|
||||
}
|
||||
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
LogUtils.DEBUG("** Parcel.removeByName Exception: " + e );
|
||||
} catch (Exception e) {
|
||||
LogUtils.DEBUG("** Parcel.removeByName Exception: " + e);
|
||||
throw new com.sun.star.lang.WrappedTargetException(e);
|
||||
}
|
||||
|
||||
}
|
||||
// rename parcel
|
||||
public void rename( String name )
|
||||
{
|
||||
public void rename(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public ParcelContainer getParent() { return parent; }
|
||||
public ParcelContainer getParent() {
|
||||
return parent;
|
||||
}
|
||||
/**
|
||||
* Returns the path of this <tt>Parcel</tt>
|
||||
*
|
||||
* @return <tt>String</tt> path to parcel
|
||||
*/
|
||||
public String getPathToParcel()
|
||||
{
|
||||
public String getPathToParcel() {
|
||||
String path = parent.getParcelContainerDir() + "/" + name;
|
||||
return path;
|
||||
}
|
||||
|
@@ -43,15 +43,15 @@ import com.sun.star.uri.XVndSunStarScriptUrl;
|
||||
* ScripingFramework specific Libraries.
|
||||
*/
|
||||
|
||||
public class ParcelContainer implements XNameAccess
|
||||
{
|
||||
public class ParcelContainer implements XNameAccess {
|
||||
protected String language;
|
||||
protected String containerUrl;
|
||||
private Collection<Parcel> parcels = new ArrayList<Parcel>(10);
|
||||
static protected XSimpleFileAccess m_xSFA;
|
||||
protected XComponentContext m_xCtx;
|
||||
private ParcelContainer parent = null;
|
||||
private Collection<ParcelContainer> childContainers = new ArrayList<ParcelContainer>(10);
|
||||
private Collection<ParcelContainer> childContainers = new
|
||||
ArrayList<ParcelContainer>(10);
|
||||
private boolean isPkgContainer = false;
|
||||
|
||||
/**
|
||||
@@ -60,7 +60,9 @@ public class ParcelContainer implements XNameAccess
|
||||
*
|
||||
* @return <tt>true</tt> if has parent <tt>false</tt> otherwise
|
||||
*/
|
||||
public boolean isUnoPkg() { return isPkgContainer; }
|
||||
public boolean isUnoPkg() {
|
||||
return isPkgContainer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -68,8 +70,7 @@ public class ParcelContainer implements XNameAccess
|
||||
*
|
||||
* @return <tt>ParcelContainer</tt> if has parent null otherwise
|
||||
*/
|
||||
public ParcelContainer parent()
|
||||
{
|
||||
public ParcelContainer parent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@@ -80,13 +81,12 @@ public class ParcelContainer implements XNameAccess
|
||||
* @return a new array of ParcelContainers. A zero
|
||||
* length array is returned if no child ParcelContainers.
|
||||
*/
|
||||
public ParcelContainer[] getChildContainers()
|
||||
{
|
||||
if ( childContainers.isEmpty() )
|
||||
{
|
||||
public ParcelContainer[] getChildContainers() {
|
||||
if (childContainers.isEmpty()) {
|
||||
return new ParcelContainer[0];
|
||||
}
|
||||
return childContainers.toArray( new ParcelContainer[childContainers.size()] );
|
||||
|
||||
return childContainers.toArray(new ParcelContainer[childContainers.size()]);
|
||||
|
||||
}
|
||||
/**
|
||||
@@ -96,9 +96,8 @@ public class ParcelContainer implements XNameAccess
|
||||
*
|
||||
* @return <tt>true</tt> if child successfully removed
|
||||
*/
|
||||
public boolean removeChildContainer( ParcelContainer child )
|
||||
{
|
||||
return childContainers.remove( child );
|
||||
public boolean removeChildContainer(ParcelContainer child) {
|
||||
return childContainers.remove(child);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,9 +106,8 @@ public class ParcelContainer implements XNameAccess
|
||||
* @param child <tt>ParcelContainer</tt> to be added.
|
||||
*
|
||||
*/
|
||||
public void addChildContainer( ParcelContainer child )
|
||||
{
|
||||
childContainers.add( child );
|
||||
public void addChildContainer(ParcelContainer child) {
|
||||
childContainers.add(child);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,19 +119,19 @@ public class ParcelContainer implements XNameAccess
|
||||
* @return child <tt>ParcelContainer</tt> or {@code null} if none
|
||||
* found.
|
||||
*/
|
||||
public ParcelContainer getChildContainer(String key)
|
||||
{
|
||||
public ParcelContainer getChildContainer(String key) {
|
||||
ParcelContainer result = null;
|
||||
for (ParcelContainer c : childContainers)
|
||||
{
|
||||
|
||||
for (ParcelContainer c : childContainers) {
|
||||
String location = ScriptMetaData.getLocationPlaceHolder(
|
||||
c.containerUrl, c.getName());
|
||||
if ( key.equals( location ) )
|
||||
{
|
||||
c.containerUrl, c.getName());
|
||||
|
||||
if (key.equals(location)) {
|
||||
result = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -147,17 +145,16 @@ public class ParcelContainer implements XNameAccess
|
||||
* @return child <tt>ParcelContainer</tt> or {@code null} if none
|
||||
* found.
|
||||
*/
|
||||
public ParcelContainer getChildContainerForURL( String containerUrl )
|
||||
{
|
||||
public ParcelContainer getChildContainerForURL(String containerUrl) {
|
||||
ParcelContainer result = null;
|
||||
for (ParcelContainer c : childContainers)
|
||||
{
|
||||
if ( containerUrl.equals( c.containerUrl ) )
|
||||
{
|
||||
|
||||
for (ParcelContainer c : childContainers) {
|
||||
if (containerUrl.equals(c.containerUrl)) {
|
||||
result = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -168,33 +165,28 @@ public class ParcelContainer implements XNameAccess
|
||||
* @return name of <tt>ParcelContainer</tt>
|
||||
* found.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
public String getName() {
|
||||
String name = null;
|
||||
|
||||
// TODO handler package ParcelContainer?
|
||||
if ( !containerUrl.startsWith( "vnd.sun.star.tdoc:" ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!containerUrl.startsWith("vnd.sun.star.tdoc:")) {
|
||||
try {
|
||||
// return name
|
||||
String decodedUrl = java.net.URLDecoder.decode( containerUrl, "UTF-8" );
|
||||
String decodedUrl = java.net.URLDecoder.decode(containerUrl, "UTF-8");
|
||||
int indexOfSlash = decodedUrl.lastIndexOf('/');
|
||||
if ( indexOfSlash != -1 )
|
||||
{
|
||||
name = decodedUrl.substring( indexOfSlash + 1 );
|
||||
|
||||
if (indexOfSlash != -1) {
|
||||
name = decodedUrl.substring(indexOfSlash + 1);
|
||||
}
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
com.sun.star.uno.RuntimeException e2 = new com.sun.star.uno.RuntimeException();
|
||||
e2.initCause(e);
|
||||
throw e2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
name = "document";
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -204,10 +196,12 @@ public class ParcelContainer implements XNameAccess
|
||||
* @param containerUrl location of this container.
|
||||
* @param language language for which entries are stored
|
||||
*/
|
||||
public ParcelContainer( XComponentContext xCtx, String containerUrl, String language ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException
|
||||
public ParcelContainer(XComponentContext xCtx, String containerUrl,
|
||||
String language) throws com.sun.star.lang.IllegalArgumentException,
|
||||
com.sun.star.lang.WrappedTargetException
|
||||
|
||||
{
|
||||
this( null, xCtx, containerUrl, language, true );
|
||||
this(null, xCtx, containerUrl, language, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,9 +212,11 @@ public class ParcelContainer implements XNameAccess
|
||||
* @param loadParcels set to <tt>true</tt> if parcels are to be loaded
|
||||
* on construction.
|
||||
*/
|
||||
public ParcelContainer( XComponentContext xCtx, String containerUrl, String language, boolean loadParcels ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException
|
||||
{
|
||||
this( null, xCtx, containerUrl, language, loadParcels );
|
||||
public ParcelContainer(XComponentContext xCtx, String containerUrl,
|
||||
String language, boolean loadParcels) throws
|
||||
com.sun.star.lang.IllegalArgumentException,
|
||||
com.sun.star.lang.WrappedTargetException {
|
||||
this(null, xCtx, containerUrl, language, loadParcels);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,10 +228,14 @@ public class ParcelContainer implements XNameAccess
|
||||
* @param loadParcels set to <tt>true</tt> if parcels are to be loaded
|
||||
* on construction.
|
||||
*/
|
||||
public ParcelContainer( ParcelContainer parent, XComponentContext xCtx, String containerUrl, String language, boolean loadParcels ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException
|
||||
public ParcelContainer(ParcelContainer parent, XComponentContext xCtx,
|
||||
String containerUrl, String language,
|
||||
boolean loadParcels) throws com.sun.star.lang.IllegalArgumentException,
|
||||
com.sun.star.lang.WrappedTargetException
|
||||
|
||||
{
|
||||
LogUtils.DEBUG("Creating ParcelContainer for " + containerUrl + " loadParcels = " + loadParcels + " language = " + language );
|
||||
LogUtils.DEBUG("Creating ParcelContainer for " + containerUrl +
|
||||
" loadParcels = " + loadParcels + " language = " + language);
|
||||
this.m_xCtx = xCtx;
|
||||
this.language = language;
|
||||
this.parent = parent;
|
||||
@@ -244,437 +244,413 @@ public class ParcelContainer implements XNameAccess
|
||||
initSimpleFileAccess();
|
||||
boolean parentIsPkgContainer = false;
|
||||
|
||||
if ( parent != null )
|
||||
{
|
||||
if (parent != null) {
|
||||
parentIsPkgContainer = parent.isUnoPkg();
|
||||
}
|
||||
|
||||
if ( containerUrl.endsWith("uno_packages") || parentIsPkgContainer )
|
||||
{
|
||||
if (containerUrl.endsWith("uno_packages") || parentIsPkgContainer) {
|
||||
isPkgContainer = true;
|
||||
}
|
||||
|
||||
if ( loadParcels )
|
||||
{
|
||||
if (loadParcels) {
|
||||
loadParcels();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getContainerURL() { return this.containerUrl; }
|
||||
public String getContainerURL() {
|
||||
return this.containerUrl;
|
||||
}
|
||||
|
||||
private synchronized void initSimpleFileAccess()
|
||||
{
|
||||
if ( m_xSFA != null )
|
||||
{
|
||||
private synchronized void initSimpleFileAccess() {
|
||||
if (m_xSFA != null) {
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
|
||||
try {
|
||||
m_xSFA = UnoRuntime.queryInterface(
|
||||
XSimpleFileAccess.class,
|
||||
m_xCtx.getServiceManager().createInstanceWithContext(
|
||||
"com.sun.star.ucb.SimpleFileAccess", m_xCtx ) );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
XSimpleFileAccess.class,
|
||||
m_xCtx.getServiceManager().createInstanceWithContext(
|
||||
"com.sun.star.ucb.SimpleFileAccess", m_xCtx));
|
||||
} catch (Exception e) {
|
||||
// TODO should throw
|
||||
LogUtils.DEBUG("Error instantiating simplefile access ");
|
||||
LogUtils.DEBUG( LogUtils.getTrace( e ) );
|
||||
LogUtils.DEBUG(LogUtils.getTrace(e));
|
||||
}
|
||||
}
|
||||
|
||||
public String getParcelContainerDir()
|
||||
{
|
||||
public String getParcelContainerDir() {
|
||||
// If this container does not represent an uno-package
|
||||
// then then it is a document, user or share
|
||||
// in each case the convention is to have a Scripts/[language]
|
||||
// dir where scripts reside
|
||||
if ( !isUnoPkg() )
|
||||
{
|
||||
return PathUtils.make_url( containerUrl , "Scripts/" + language.toLowerCase() );
|
||||
if (!isUnoPkg()) {
|
||||
return PathUtils.make_url(containerUrl , "Scripts/" + language.toLowerCase());
|
||||
}
|
||||
|
||||
return containerUrl;
|
||||
}
|
||||
|
||||
public Object getByName( String aName ) throws com.sun.star.container.NoSuchElementException, WrappedTargetException
|
||||
{
|
||||
public Object getByName(String aName) throws
|
||||
com.sun.star.container.NoSuchElementException, WrappedTargetException {
|
||||
Parcel parcel = null;
|
||||
try
|
||||
{
|
||||
if ( hasElements() )
|
||||
{
|
||||
for (Parcel parcelToCheck : parcels)
|
||||
{
|
||||
if ( parcelToCheck.getName().equals( aName ) )
|
||||
{
|
||||
parcel = parcelToCheck;
|
||||
break;
|
||||
|
||||
try {
|
||||
if (hasElements()) {
|
||||
for (Parcel parcelToCheck : parcels) {
|
||||
if (parcelToCheck.getName().equals(aName)) {
|
||||
parcel = parcelToCheck;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
throw new WrappedTargetException(e);
|
||||
}
|
||||
if ( parcel == null )
|
||||
{
|
||||
throw new com.sun.star.container.NoSuchElementException( "Macro Library " + aName + " not found" );
|
||||
|
||||
if (parcel == null) {
|
||||
throw new com.sun.star.container.NoSuchElementException("Macro Library " + aName
|
||||
+ " not found");
|
||||
}
|
||||
|
||||
return parcel;
|
||||
}
|
||||
|
||||
public String[] getElementNames()
|
||||
{
|
||||
if ( hasElements() )
|
||||
{
|
||||
Parcel[] theParcels = parcels.toArray( new Parcel[parcels.size()] );
|
||||
public String[] getElementNames() {
|
||||
if (hasElements()) {
|
||||
Parcel[] theParcels = parcels.toArray(new Parcel[parcels.size()]);
|
||||
String[] names = new String[ theParcels.length ];
|
||||
for ( int count = 0; count < names.length; count++ )
|
||||
{
|
||||
|
||||
for (int count = 0; count < names.length; count++) {
|
||||
names[count] = theParcels[ count ].getName();
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
return new String[0];
|
||||
}
|
||||
public boolean hasByName( String aName )
|
||||
{
|
||||
public boolean hasByName(String aName) {
|
||||
boolean isFound = false;
|
||||
try
|
||||
{
|
||||
if ( getByName( aName ) != null )
|
||||
{
|
||||
|
||||
try {
|
||||
if (getByName(aName) != null) {
|
||||
isFound = true;
|
||||
}
|
||||
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
} catch (Exception e) {
|
||||
//TODO - handle trace
|
||||
}
|
||||
|
||||
return isFound;
|
||||
}
|
||||
public Type getElementType()
|
||||
{
|
||||
public Type getElementType() {
|
||||
return new Type();
|
||||
}
|
||||
public boolean hasElements()
|
||||
{
|
||||
public boolean hasElements() {
|
||||
return !(parcels == null || parcels.isEmpty());
|
||||
}
|
||||
|
||||
private void loadParcels() throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException
|
||||
{
|
||||
try
|
||||
{
|
||||
LogUtils.DEBUG("About to load parcels from " + containerUrl );
|
||||
if ( m_xSFA.isFolder( getParcelContainerDir() ) )
|
||||
{
|
||||
LogUtils.DEBUG( getParcelContainerDir() + " is a folder " );
|
||||
String[] children = m_xSFA.getFolderContents( getParcelContainerDir(), true );
|
||||
private void loadParcels() throws com.sun.star.lang.IllegalArgumentException,
|
||||
com.sun.star.lang.WrappedTargetException {
|
||||
try {
|
||||
LogUtils.DEBUG("About to load parcels from " + containerUrl);
|
||||
|
||||
if (m_xSFA.isFolder(getParcelContainerDir())) {
|
||||
LogUtils.DEBUG(getParcelContainerDir() + " is a folder ");
|
||||
String[] children = m_xSFA.getFolderContents(getParcelContainerDir(), true);
|
||||
parcels = new ArrayList<Parcel>(children.length);
|
||||
for (String child : children)
|
||||
{
|
||||
|
||||
for (String child : children) {
|
||||
LogUtils.DEBUG("Processing " + child);
|
||||
try
|
||||
{
|
||||
|
||||
try {
|
||||
loadParcel(child);
|
||||
}
|
||||
catch (java.lang.Exception e)
|
||||
{
|
||||
} catch (java.lang.Exception e) {
|
||||
// print an error message and move on to
|
||||
// the next parcel
|
||||
LogUtils.DEBUG("ParcelContainer.loadParcels caught " + e.getClass().getName() + " exception loading parcel " + child + ": " + e.getMessage());
|
||||
LogUtils.DEBUG("ParcelContainer.loadParcels caught " + e.getClass().getName() +
|
||||
" exception loading parcel " + child + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogUtils.DEBUG(" ParcelCOntainer.loadParcels " + getParcelContainerDir() + " is not a folder ");
|
||||
} else {
|
||||
LogUtils.DEBUG(" ParcelCOntainer.loadParcels " + getParcelContainerDir() +
|
||||
" is not a folder ");
|
||||
}
|
||||
|
||||
}
|
||||
catch ( com.sun.star.ucb.CommandAbortedException e )
|
||||
{
|
||||
LogUtils.DEBUG("ParcelContainer.loadParcels caught exception processing folders for " + getParcelContainerDir() );
|
||||
LogUtils.DEBUG("TRACE: " + LogUtils.getTrace(e) );
|
||||
} catch (com.sun.star.ucb.CommandAbortedException e) {
|
||||
LogUtils.DEBUG("ParcelContainer.loadParcels caught exception processing folders for "
|
||||
+ getParcelContainerDir());
|
||||
LogUtils.DEBUG("TRACE: " + LogUtils.getTrace(e));
|
||||
throw new com.sun.star.lang.WrappedTargetException(e);
|
||||
}
|
||||
catch ( com.sun.star.uno.Exception e )
|
||||
{
|
||||
LogUtils.DEBUG("ParcelContainer.loadParcels caught exception processing folders for " + getParcelContainerDir() );
|
||||
LogUtils.DEBUG("TRACE: " + LogUtils.getTrace(e) );
|
||||
} catch (com.sun.star.uno.Exception e) {
|
||||
LogUtils.DEBUG("ParcelContainer.loadParcels caught exception processing folders for "
|
||||
+ getParcelContainerDir());
|
||||
LogUtils.DEBUG("TRACE: " + LogUtils.getTrace(e));
|
||||
throw new com.sun.star.lang.WrappedTargetException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public XNameContainer createParcel(String name) throws ElementExistException, com.sun.star.lang.WrappedTargetException
|
||||
{
|
||||
public XNameContainer createParcel(String name) throws ElementExistException,
|
||||
com.sun.star.lang.WrappedTargetException {
|
||||
Parcel p = null;
|
||||
if ( hasByName( name ) )
|
||||
{
|
||||
throw new ElementExistException( "Parcel " + name + " already exists" );
|
||||
|
||||
if (hasByName(name)) {
|
||||
throw new ElementExistException("Parcel " + name + " already exists");
|
||||
}
|
||||
String pathToParcel = PathUtils.make_url( getParcelContainerDir() , name );
|
||||
|
||||
try
|
||||
{
|
||||
LogUtils.DEBUG("ParcelContainer.createParcel, creating folder " + pathToParcel );
|
||||
m_xSFA.createFolder( pathToParcel );
|
||||
String pathToParcel = PathUtils.make_url(getParcelContainerDir() , name);
|
||||
|
||||
LogUtils.DEBUG("ParcelContainer.createParcel, folder " + pathToParcel + " created ");
|
||||
try {
|
||||
LogUtils.DEBUG("ParcelContainer.createParcel, creating folder " + pathToParcel);
|
||||
m_xSFA.createFolder(pathToParcel);
|
||||
|
||||
LogUtils.DEBUG("ParcelContainer.createParcel, folder " + pathToParcel +
|
||||
" created ");
|
||||
|
||||
ParcelDescriptor pd = new ParcelDescriptor();
|
||||
pd.setLanguage( language );
|
||||
String parcelDesc = PathUtils.make_url( pathToParcel, ParcelDescriptor.PARCEL_DESCRIPTOR_NAME );
|
||||
XSimpleFileAccess2 xSFA2 = UnoRuntime.queryInterface( XSimpleFileAccess2.class, m_xSFA );
|
||||
if ( xSFA2 != null )
|
||||
{
|
||||
LogUtils.DEBUG("createParcel() Using XSIMPLEFILEACCESS2 " + parcelDesc );
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream( 1024 );
|
||||
pd.write( bos );
|
||||
bos.close();
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream( bos.toByteArray() );
|
||||
XInputStreamImpl xis = new XInputStreamImpl( bis );
|
||||
xSFA2.writeFile( parcelDesc, xis );
|
||||
xis.closeInput();
|
||||
p = loadParcel( pathToParcel );
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
pd.setLanguage(language);
|
||||
String parcelDesc = PathUtils.make_url(pathToParcel,
|
||||
ParcelDescriptor.PARCEL_DESCRIPTOR_NAME);
|
||||
XSimpleFileAccess2 xSFA2 = UnoRuntime.queryInterface(XSimpleFileAccess2.class,
|
||||
m_xSFA);
|
||||
|
||||
LogUtils.DEBUG("createParcel() Exception while attempting to create = " + name );
|
||||
if (xSFA2 != null) {
|
||||
LogUtils.DEBUG("createParcel() Using XSIMPLEFILEACCESS2 " + parcelDesc);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
|
||||
pd.write(bos);
|
||||
bos.close();
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
|
||||
XInputStreamImpl xis = new XInputStreamImpl(bis);
|
||||
xSFA2.writeFile(parcelDesc, xis);
|
||||
xis.closeInput();
|
||||
p = loadParcel(pathToParcel);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
LogUtils.DEBUG("createParcel() Exception while attempting to create = " + name);
|
||||
throw new com.sun.star.lang.WrappedTargetException(e);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
public Parcel loadParcel( String parcelUrl ) throws com.sun.star.lang.WrappedTargetException, com.sun.star.lang.IllegalArgumentException
|
||||
{
|
||||
public Parcel loadParcel(String parcelUrl) throws
|
||||
com.sun.star.lang.WrappedTargetException,
|
||||
com.sun.star.lang.IllegalArgumentException {
|
||||
|
||||
String parcelDescUrl = PathUtils.make_url( parcelUrl, ParcelDescriptor.PARCEL_DESCRIPTOR_NAME );
|
||||
String parcelDescUrl = PathUtils.make_url(parcelUrl,
|
||||
ParcelDescriptor.PARCEL_DESCRIPTOR_NAME);
|
||||
Parcel parcel = null;
|
||||
|
||||
XInputStream xis = null;
|
||||
InputStream is = null;
|
||||
|
||||
try
|
||||
{
|
||||
if ( m_xSFA.exists( parcelDescUrl ) )
|
||||
{
|
||||
LogUtils.DEBUG("ParcelContainer.loadParcel opening " + parcelDescUrl );
|
||||
xis = m_xSFA.openFileRead( parcelDescUrl );
|
||||
is = new XInputStreamWrapper( xis );
|
||||
try {
|
||||
if (m_xSFA.exists(parcelDescUrl)) {
|
||||
LogUtils.DEBUG("ParcelContainer.loadParcel opening " + parcelDescUrl);
|
||||
xis = m_xSFA.openFileRead(parcelDescUrl);
|
||||
is = new XInputStreamWrapper(xis);
|
||||
|
||||
ParcelDescriptor pd = new ParcelDescriptor(is) ;
|
||||
try
|
||||
{
|
||||
|
||||
try {
|
||||
is.close();
|
||||
is = null;
|
||||
} catch (Exception e) {
|
||||
LogUtils.DEBUG("ParcelContainer.loadParcel Exception when closing stream for "
|
||||
+ parcelDescUrl + " :" + e);
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
LogUtils.DEBUG("ParcelContainer.loadParcel Exception when closing stream for " + parcelDescUrl + " :" + e );
|
||||
}
|
||||
LogUtils.DEBUG("ParcelContainer.loadParcel closed " + parcelDescUrl );
|
||||
if ( !pd.getLanguage().equals( language ) )
|
||||
{
|
||||
|
||||
LogUtils.DEBUG("ParcelContainer.loadParcel closed " + parcelDescUrl);
|
||||
|
||||
if (!pd.getLanguage().equals(language)) {
|
||||
LogUtils.DEBUG("ParcelContainer.loadParcel Language of Parcel does not match this container ");
|
||||
return null;
|
||||
}
|
||||
LogUtils.DEBUG("Processing " + parcelDescUrl + " closed " );
|
||||
|
||||
LogUtils.DEBUG("Processing " + parcelDescUrl + " closed ");
|
||||
|
||||
int indexOfSlash = parcelUrl.lastIndexOf('/');
|
||||
String name = parcelUrl.substring( indexOfSlash + 1 );
|
||||
String name = parcelUrl.substring(indexOfSlash + 1);
|
||||
|
||||
parcel = new Parcel( m_xSFA, this, pd, name );
|
||||
parcel = new Parcel(m_xSFA, this, pd, name);
|
||||
|
||||
LogUtils.DEBUG(" ParcelContainer.loadParcel created parcel for " + parcelDescUrl + " for language " + language );
|
||||
parcels.add( parcel );
|
||||
LogUtils.DEBUG(" ParcelContainer.loadParcel created parcel for " + parcelDescUrl
|
||||
+ " for language " + language);
|
||||
parcels.add(parcel);
|
||||
} else {
|
||||
throw new java.io.IOException(parcelDescUrl + " does NOT exist!");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new java.io.IOException( parcelDescUrl + " does NOT exist!");
|
||||
}
|
||||
}
|
||||
catch ( com.sun.star.ucb.CommandAbortedException e )
|
||||
{
|
||||
} catch (com.sun.star.ucb.CommandAbortedException e) {
|
||||
|
||||
LogUtils.DEBUG("loadParcel() Exception while accessing filesystem url = " + parcelDescUrl + e );
|
||||
LogUtils.DEBUG("loadParcel() Exception while accessing filesystem url = " +
|
||||
parcelDescUrl + e);
|
||||
throw new com.sun.star.lang.WrappedTargetException(e);
|
||||
}
|
||||
catch ( java.io.IOException e )
|
||||
{
|
||||
LogUtils.DEBUG("ParcelContainer.loadParcel() caught IOException while accessing " + parcelDescUrl + ": " + e );
|
||||
} catch (java.io.IOException e) {
|
||||
LogUtils.DEBUG("ParcelContainer.loadParcel() caught IOException while accessing "
|
||||
+ parcelDescUrl + ": " + e);
|
||||
throw new com.sun.star.lang.WrappedTargetException(e);
|
||||
}
|
||||
catch ( com.sun.star.uno.Exception e )
|
||||
{
|
||||
} catch (com.sun.star.uno.Exception e) {
|
||||
|
||||
LogUtils.DEBUG("loadParcel() Exception while accessing filesystem url = " + parcelDescUrl + e );
|
||||
LogUtils.DEBUG("loadParcel() Exception while accessing filesystem url = " +
|
||||
parcelDescUrl + e);
|
||||
throw new com.sun.star.lang.WrappedTargetException(e);
|
||||
}
|
||||
|
||||
finally
|
||||
{
|
||||
if ( is != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close(); // is will close xis
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
catch ( Exception ignore )
|
||||
{
|
||||
}
|
||||
}
|
||||
else if ( xis != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
} else if (xis != null) {
|
||||
try {
|
||||
xis.closeInput();
|
||||
}
|
||||
catch ( Exception ignore )
|
||||
{
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parcel;
|
||||
}
|
||||
public void renameParcel(String oldName, String newName) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException
|
||||
{
|
||||
LogUtils.DEBUG(" ** ParcelContainer Renaming parcel " + oldName + " to " + newName );
|
||||
LogUtils.DEBUG(" ** ParcelContainer is " + this );
|
||||
Parcel p = (Parcel)getByName( oldName );
|
||||
if ( p == null )
|
||||
{
|
||||
throw new com.sun.star.container.NoSuchElementException( "No parcel named " + oldName );
|
||||
public void renameParcel(String oldName,
|
||||
String newName) throws com.sun.star.container.NoSuchElementException,
|
||||
com.sun.star.lang.WrappedTargetException {
|
||||
LogUtils.DEBUG(" ** ParcelContainer Renaming parcel " + oldName + " to " +
|
||||
newName);
|
||||
LogUtils.DEBUG(" ** ParcelContainer is " + this);
|
||||
Parcel p = (Parcel)getByName(oldName);
|
||||
|
||||
if (p == null) {
|
||||
throw new com.sun.star.container.NoSuchElementException("No parcel named " +
|
||||
oldName);
|
||||
}
|
||||
String oldParcelDirUrl = PathUtils.make_url( getParcelContainerDir(),
|
||||
oldName );
|
||||
String newParcelDirUrl = PathUtils.make_url( getParcelContainerDir(),
|
||||
newName );
|
||||
try
|
||||
{
|
||||
if (!m_xSFA.isFolder( oldParcelDirUrl ) )
|
||||
{
|
||||
Exception e = new com.sun.star.io.IOException("Invalid Parcel directory: " + oldName );
|
||||
|
||||
String oldParcelDirUrl = PathUtils.make_url(getParcelContainerDir(),
|
||||
oldName);
|
||||
String newParcelDirUrl = PathUtils.make_url(getParcelContainerDir(),
|
||||
newName);
|
||||
|
||||
try {
|
||||
if (!m_xSFA.isFolder(oldParcelDirUrl)) {
|
||||
Exception e = new com.sun.star.io.IOException("Invalid Parcel directory: " +
|
||||
oldName);
|
||||
throw new com.sun.star.lang.WrappedTargetException(e);
|
||||
}
|
||||
LogUtils.DEBUG(" ** ParcelContainer Renaming folder " + oldParcelDirUrl + " to " + newParcelDirUrl );
|
||||
m_xSFA.move( oldParcelDirUrl, newParcelDirUrl );
|
||||
}
|
||||
catch ( com.sun.star.ucb.CommandAbortedException ce )
|
||||
{
|
||||
LogUtils.DEBUG(" ** ParcelContainer Renaming failed with " + ce );
|
||||
|
||||
LogUtils.DEBUG(" ** ParcelContainer Renaming folder " + oldParcelDirUrl + " to "
|
||||
+ newParcelDirUrl);
|
||||
m_xSFA.move(oldParcelDirUrl, newParcelDirUrl);
|
||||
} catch (com.sun.star.ucb.CommandAbortedException ce) {
|
||||
LogUtils.DEBUG(" ** ParcelContainer Renaming failed with " + ce);
|
||||
throw new com.sun.star.lang.WrappedTargetException(ce);
|
||||
}
|
||||
catch ( com.sun.star.uno.Exception e )
|
||||
{
|
||||
LogUtils.DEBUG(" ** ParcelContainer Renaming failed with " + e );
|
||||
} catch (com.sun.star.uno.Exception e) {
|
||||
LogUtils.DEBUG(" ** ParcelContainer Renaming failed with " + e);
|
||||
throw new com.sun.star.lang.WrappedTargetException(e);
|
||||
}
|
||||
|
||||
p.rename( newName );
|
||||
p.rename(newName);
|
||||
}
|
||||
// removes but doesn't physically delele parcel from container
|
||||
public boolean removeParcel(String name) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException
|
||||
{
|
||||
Parcel p = (Parcel)getByName( name );
|
||||
if ( p == null )
|
||||
{
|
||||
throw new com.sun.star.container.NoSuchElementException("No parcel named " + name );
|
||||
public boolean removeParcel(String name) throws
|
||||
com.sun.star.container.NoSuchElementException,
|
||||
com.sun.star.lang.WrappedTargetException {
|
||||
Parcel p = (Parcel)getByName(name);
|
||||
|
||||
if (p == null) {
|
||||
throw new com.sun.star.container.NoSuchElementException("No parcel named " +
|
||||
name);
|
||||
}
|
||||
|
||||
return parcels.remove( p );
|
||||
return parcels.remove(p);
|
||||
}
|
||||
public boolean deleteParcel(String name) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException
|
||||
{
|
||||
LogUtils.DEBUG( "deleteParcel for containerURL " + containerUrl + " name = " + name + " Langueg = " + language );
|
||||
public boolean deleteParcel(String name) throws
|
||||
com.sun.star.container.NoSuchElementException,
|
||||
com.sun.star.lang.WrappedTargetException {
|
||||
LogUtils.DEBUG("deleteParcel for containerURL " + containerUrl + " name = " +
|
||||
name + " Langueg = " + language);
|
||||
|
||||
Parcel p = (Parcel)getByName( name );
|
||||
if ( p == null )
|
||||
{
|
||||
throw new com.sun.star.container.NoSuchElementException("No parcel named " + name );
|
||||
Parcel p = (Parcel)getByName(name);
|
||||
|
||||
if (p == null) {
|
||||
throw new com.sun.star.container.NoSuchElementException("No parcel named " +
|
||||
name);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
String pathToParcel = PathUtils.make_url( getParcelContainerDir(), name );
|
||||
m_xSFA.kill( pathToParcel );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
LogUtils.DEBUG("Error deleteing parcel " + name );
|
||||
try {
|
||||
String pathToParcel = PathUtils.make_url(getParcelContainerDir(), name);
|
||||
m_xSFA.kill(pathToParcel);
|
||||
} catch (Exception e) {
|
||||
LogUtils.DEBUG("Error deleteing parcel " + name);
|
||||
throw new com.sun.star.lang.WrappedTargetException(e);
|
||||
}
|
||||
|
||||
return parcels.remove( p );
|
||||
return parcels.remove(p);
|
||||
}
|
||||
|
||||
public String getLanguage() { return language; }
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public ScriptMetaData findScript( ParsedScriptUri parsedUri ) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException
|
||||
{
|
||||
Parcel p = (Parcel)getByName( parsedUri.parcel);
|
||||
ScriptMetaData scriptData = (ScriptMetaData)p.getByName( parsedUri.function);
|
||||
LogUtils.DEBUG("** found script data for " + parsedUri.function + " script is " + scriptData );
|
||||
public ScriptMetaData findScript(ParsedScriptUri parsedUri) throws
|
||||
com.sun.star.container.NoSuchElementException,
|
||||
com.sun.star.lang.WrappedTargetException {
|
||||
Parcel p = (Parcel)getByName(parsedUri.parcel);
|
||||
ScriptMetaData scriptData = (ScriptMetaData)p.getByName(parsedUri.function);
|
||||
LogUtils.DEBUG("** found script data for " + parsedUri.function + " script is "
|
||||
+ scriptData);
|
||||
return scriptData;
|
||||
|
||||
}
|
||||
public ParsedScriptUri parseScriptUri( String scriptURI ) throws com.sun.star.lang.IllegalArgumentException
|
||||
{
|
||||
public ParsedScriptUri parseScriptUri(String scriptURI) throws
|
||||
com.sun.star.lang.IllegalArgumentException {
|
||||
|
||||
XMultiComponentFactory xMcFac = null;
|
||||
XUriReferenceFactory xFac = null;
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
xMcFac = m_xCtx.getServiceManager();
|
||||
xFac = UnoRuntime.queryInterface( XUriReferenceFactory.class,
|
||||
xMcFac.createInstanceWithContext(
|
||||
"com.sun.star.uri.UriReferenceFactory", m_xCtx ) );
|
||||
}
|
||||
catch( com.sun.star.uno.Exception e )
|
||||
{
|
||||
LogUtils.DEBUG("Problems parsing URL:" + e.toString() );
|
||||
xFac = UnoRuntime.queryInterface(XUriReferenceFactory.class,
|
||||
xMcFac.createInstanceWithContext(
|
||||
"com.sun.star.uri.UriReferenceFactory", m_xCtx));
|
||||
} catch (com.sun.star.uno.Exception e) {
|
||||
LogUtils.DEBUG("Problems parsing URL:" + e.toString());
|
||||
throw new com.sun.star.lang.IllegalArgumentException(e, "Problems parsing URL");
|
||||
}
|
||||
if ( xFac == null )
|
||||
{
|
||||
|
||||
if (xFac == null) {
|
||||
LogUtils.DEBUG("Failed to create UrlReference factory");
|
||||
throw new com.sun.star.lang.IllegalArgumentException( "Failed to create UrlReference factory for url " + scriptURI );
|
||||
throw new com.sun.star.lang.IllegalArgumentException("Failed to create UrlReference factory for url "
|
||||
+ scriptURI);
|
||||
}
|
||||
|
||||
XUriReference uriRef = xFac.parse( scriptURI );
|
||||
XVndSunStarScriptUrl sfUri = UnoRuntime.queryInterface( XVndSunStarScriptUrl.class, uriRef );
|
||||
XUriReference uriRef = xFac.parse(scriptURI);
|
||||
XVndSunStarScriptUrl sfUri = UnoRuntime.queryInterface(
|
||||
XVndSunStarScriptUrl.class, uriRef);
|
||||
|
||||
if ( sfUri == null )
|
||||
{
|
||||
if (sfUri == null) {
|
||||
LogUtils.DEBUG("Failed to parse url");
|
||||
throw new com.sun.star.lang.IllegalArgumentException( "Failed to parse url " + scriptURI );
|
||||
throw new com.sun.star.lang.IllegalArgumentException("Failed to parse url " +
|
||||
scriptURI);
|
||||
}
|
||||
|
||||
ParsedScriptUri parsedUri = new ParsedScriptUri();
|
||||
parsedUri.function= sfUri.getName();
|
||||
parsedUri.function = sfUri.getName();
|
||||
parsedUri.parcel = "";
|
||||
|
||||
// parse parcel name;
|
||||
StringTokenizer tokenizer = new StringTokenizer( parsedUri.function, "." );
|
||||
StringTokenizer tokenizer = new StringTokenizer(parsedUri.function, ".");
|
||||
|
||||
if ( tokenizer.hasMoreElements() )
|
||||
{
|
||||
if (tokenizer.hasMoreElements()) {
|
||||
parsedUri.parcel = (String)tokenizer.nextElement();
|
||||
LogUtils.DEBUG("** parcelName = " + parsedUri.parcel );
|
||||
LogUtils.DEBUG("** parcelName = " + parsedUri.parcel);
|
||||
}
|
||||
|
||||
if ( parsedUri.function != null && ( parsedUri.function.length() > 0 ) )
|
||||
{
|
||||
if (parsedUri.function != null && (parsedUri.function.length() > 0)) {
|
||||
// strip out parcel name
|
||||
parsedUri.function = parsedUri.function.substring( parsedUri.parcel.length() + 1);
|
||||
parsedUri.function = parsedUri.function.substring(parsedUri.parcel.length() +
|
||||
1);
|
||||
}
|
||||
|
||||
// parse location
|
||||
@@ -685,11 +661,11 @@ public ParsedScriptUri parseScriptUri( String scriptURI ) throws com.sun.star.l
|
||||
// time its got to here
|
||||
|
||||
LogUtils.DEBUG("** location = " + parsedUri.location +
|
||||
"\nfunction = " + parsedUri.function +
|
||||
"\nparcel = " + parsedUri.parcel +
|
||||
"\nlocation = " + parsedUri.location );
|
||||
"\nfunction = " + parsedUri.function +
|
||||
"\nparcel = " + parsedUri.parcel +
|
||||
"\nlocation = " + parsedUri.location);
|
||||
return parsedUri;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -38,10 +38,11 @@ public class ParcelDescriptor {
|
||||
|
||||
// File name to be used for parcel descriptor files
|
||||
public static final String
|
||||
PARCEL_DESCRIPTOR_NAME = "parcel-descriptor.xml";
|
||||
PARCEL_DESCRIPTOR_NAME = "parcel-descriptor.xml";
|
||||
|
||||
// Collection of all ParcelDescriptor created for files
|
||||
private static final Map<File,ParcelDescriptor> PARCEL_DESCRIPTOR_MAP = new HashMap<File,ParcelDescriptor>(5);
|
||||
private static final Map<File, ParcelDescriptor> PARCEL_DESCRIPTOR_MAP = new
|
||||
HashMap<File, ParcelDescriptor>(5);
|
||||
|
||||
// This is the default contents of a parcel descriptor to be used when
|
||||
// creating empty descriptors
|
||||
@@ -53,7 +54,7 @@ public class ParcelDescriptor {
|
||||
private File file = null;
|
||||
private Document document = null;
|
||||
private String language = null;
|
||||
private Map<String,String> languagedepprops = new HashMap<String,String>(3);
|
||||
private Map<String, String> languagedepprops = new HashMap<String, String>(3);
|
||||
|
||||
|
||||
|
||||
@@ -61,11 +62,11 @@ public class ParcelDescriptor {
|
||||
|
||||
public ParcelDescriptor() throws IOException {
|
||||
ByteArrayInputStream bis = null;
|
||||
|
||||
try {
|
||||
bis = new ByteArrayInputStream(EMPTY_DOCUMENT);
|
||||
this.document = XMLParserFactory.getParser().parse(bis);
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
if (bis != null)
|
||||
bis.close();
|
||||
}
|
||||
@@ -89,27 +90,28 @@ public class ParcelDescriptor {
|
||||
|
||||
if (file.exists()) {
|
||||
FileInputStream fis = null;
|
||||
|
||||
try {
|
||||
fis = new FileInputStream(file);
|
||||
this.document = XMLParserFactory.getParser().parse(fis);
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
if (fis != null)
|
||||
fis.close();
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ByteArrayInputStream bis = null;
|
||||
|
||||
try {
|
||||
bis = new ByteArrayInputStream(EMPTY_DOCUMENT);
|
||||
this.document = XMLParserFactory.getParser().parse(bis);
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
if (bis != null)
|
||||
bis.close();
|
||||
}
|
||||
|
||||
setLanguage(language);
|
||||
}
|
||||
|
||||
initLanguageProperties();
|
||||
}
|
||||
|
||||
@@ -128,6 +130,7 @@ public class ParcelDescriptor {
|
||||
language = e.getAttribute("language");
|
||||
}
|
||||
}
|
||||
|
||||
return language;
|
||||
}
|
||||
|
||||
@@ -138,8 +141,7 @@ public class ParcelDescriptor {
|
||||
try {
|
||||
Element e = document.getDocumentElement();
|
||||
e.setAttribute("language", language);
|
||||
}
|
||||
catch (DOMException de) {
|
||||
} catch (DOMException de) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,7 +158,7 @@ public class ParcelDescriptor {
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
String language, languagename, logicalname, description = "";
|
||||
Map<String,String> langProps = new HashMap<String,String>();
|
||||
Map<String, String> langProps = new HashMap<String, String>();
|
||||
NodeList nl;
|
||||
Element tmp;
|
||||
|
||||
@@ -164,6 +166,7 @@ public class ParcelDescriptor {
|
||||
language = scriptElement.getAttribute("language");
|
||||
|
||||
nl = scriptElement.getElementsByTagName("logicalname");
|
||||
|
||||
if (nl == null)
|
||||
logicalname = "";
|
||||
else {
|
||||
@@ -173,15 +176,13 @@ public class ParcelDescriptor {
|
||||
|
||||
// get the text of the description element
|
||||
nl = scriptElement.getElementsByTagName("locale");
|
||||
if (nl != null)
|
||||
{
|
||||
|
||||
if (nl != null) {
|
||||
nl = nl.item(0).getChildNodes();
|
||||
if (nl != null)
|
||||
{
|
||||
for (int j = 0 ; j < nl.getLength(); j++)
|
||||
{
|
||||
if (nl.item(j).getNodeName().equals("description"))
|
||||
{
|
||||
|
||||
if (nl != null) {
|
||||
for (int j = 0 ; j < nl.getLength(); j++) {
|
||||
if (nl.item(j).getNodeName().equals("description")) {
|
||||
CharacterData cd =
|
||||
(CharacterData)nl.item(j).getFirstChild();
|
||||
description = cd.getData().trim();
|
||||
@@ -191,36 +192,41 @@ public class ParcelDescriptor {
|
||||
}
|
||||
|
||||
nl = scriptElement.getElementsByTagName("functionname");
|
||||
|
||||
if (nl == null) {
|
||||
languagename = "";
|
||||
} else {
|
||||
tmp = (Element)nl.item(0);
|
||||
languagename = tmp.getAttribute("value");
|
||||
}
|
||||
|
||||
nl = scriptElement.getElementsByTagName("languagedepprops");
|
||||
if ( nl != null && nl.getLength() > 0 )
|
||||
{
|
||||
|
||||
if (nl != null && nl.getLength() > 0) {
|
||||
|
||||
NodeList props = ((Element)nl.item(0)).getElementsByTagName("prop");
|
||||
if ( props != null )
|
||||
{
|
||||
for ( int j=0; j < props.getLength(); j++ )
|
||||
{
|
||||
|
||||
if (props != null) {
|
||||
for (int j = 0; j < props.getLength(); j++) {
|
||||
tmp = (Element)props.item(j);
|
||||
String key = tmp.getAttribute("name");
|
||||
String val = tmp.getAttribute("value");
|
||||
langProps.put( key,val );
|
||||
langProps.put(key, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
ScriptEntry entry = new ScriptEntry(language, languagename, "", langProps,description);
|
||||
|
||||
ScriptEntry entry = new ScriptEntry(language, languagename, "", langProps,
|
||||
description);
|
||||
scripts.add(entry);
|
||||
}
|
||||
|
||||
return scripts.toArray(new ScriptEntry[scripts.size()]);
|
||||
}
|
||||
|
||||
public void setScriptEntries(ScriptEntry[] scripts) {
|
||||
clearEntries();
|
||||
|
||||
for (ScriptEntry script : scripts) {
|
||||
addScriptEntry(script);
|
||||
}
|
||||
@@ -228,6 +234,7 @@ public class ParcelDescriptor {
|
||||
|
||||
public void setScriptEntries(Iterator<ScriptEntry> scripts) {
|
||||
clearEntries();
|
||||
|
||||
while (scripts.hasNext())
|
||||
addScriptEntry(scripts.next());
|
||||
}
|
||||
@@ -271,13 +278,11 @@ public class ParcelDescriptor {
|
||||
int len;
|
||||
|
||||
if ((scriptNodes = document.getElementsByTagName("script")) != null &&
|
||||
(len = scriptNodes.getLength()) != 0)
|
||||
{
|
||||
(len = scriptNodes.getLength()) != 0) {
|
||||
for (int i = len - 1; i >= 0; i--) {
|
||||
try {
|
||||
main.removeChild(scriptNodes.item(i));
|
||||
}
|
||||
catch (DOMException de) {
|
||||
} catch (DOMException de) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
@@ -290,8 +295,7 @@ public class ParcelDescriptor {
|
||||
int len;
|
||||
|
||||
if ((scriptNodes = document.getElementsByTagName("script")) != null &&
|
||||
(len = scriptNodes.getLength()) != 0)
|
||||
{
|
||||
(len = scriptNodes.getLength()) != 0) {
|
||||
for (int i = len - 1; i >= 0; i--) {
|
||||
try {
|
||||
Element scriptElement = (Element)scriptNodes.item(i);
|
||||
@@ -299,6 +303,7 @@ public class ParcelDescriptor {
|
||||
|
||||
NodeList nl =
|
||||
scriptElement.getElementsByTagName("functionname");
|
||||
|
||||
if (nl == null) {
|
||||
continue;
|
||||
} else {
|
||||
@@ -309,8 +314,7 @@ public class ParcelDescriptor {
|
||||
if (languagename.equals(script.getLanguageName())) {
|
||||
main.removeChild(scriptElement);
|
||||
}
|
||||
}
|
||||
catch (DOMException de) {
|
||||
} catch (DOMException de) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
@@ -332,10 +336,11 @@ public class ParcelDescriptor {
|
||||
|
||||
tempitem = document.createElement("description");
|
||||
String description = script.getDescription();
|
||||
if (description == null || description.length() == 0)
|
||||
{
|
||||
|
||||
if (description == null || description.length() == 0) {
|
||||
description = script.getLogicalName();
|
||||
}
|
||||
|
||||
tempitem.appendChild(document.createTextNode(description));
|
||||
item.appendChild(tempitem);
|
||||
|
||||
@@ -354,6 +359,7 @@ public class ParcelDescriptor {
|
||||
item = document.createElement("languagedepprops");
|
||||
|
||||
Iterator<String> iter = languagedepprops.keySet().iterator();
|
||||
|
||||
while (iter.hasNext()) {
|
||||
tempitem = document.createElement("prop");
|
||||
key = iter.next();
|
||||
@@ -361,6 +367,7 @@ public class ParcelDescriptor {
|
||||
tempitem.setAttribute("value", languagedepprops.get(key));
|
||||
item.appendChild(tempitem);
|
||||
}
|
||||
|
||||
root.appendChild(item);
|
||||
}
|
||||
|
||||
|
@@ -17,8 +17,7 @@
|
||||
*/
|
||||
package com.sun.star.script.framework.container;
|
||||
|
||||
public class ParsedScriptUri
|
||||
{
|
||||
public class ParsedScriptUri {
|
||||
|
||||
public String location;
|
||||
public String function;
|
||||
|
@@ -27,7 +27,7 @@ public class ScriptEntry implements Cloneable {
|
||||
private String logicalname = "";
|
||||
private String description = "";
|
||||
|
||||
private Map<String,String> languagedepprops;
|
||||
private Map<String, String> languagedepprops;
|
||||
|
||||
public ScriptEntry(String language, String languagename,
|
||||
String location) {
|
||||
@@ -39,11 +39,10 @@ public class ScriptEntry implements Cloneable {
|
||||
// as logical name also
|
||||
this.logicalname = languagename;
|
||||
this.location = location;
|
||||
this.languagedepprops = new HashMap<String,String>();
|
||||
this.languagedepprops = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
public ScriptEntry(ScriptEntry entry)
|
||||
{
|
||||
public ScriptEntry(ScriptEntry entry) {
|
||||
this.language = entry.language;
|
||||
this.languagename = entry.languagename;
|
||||
this.logicalname = entry.languagename;
|
||||
@@ -53,15 +52,15 @@ public class ScriptEntry implements Cloneable {
|
||||
}
|
||||
|
||||
public ScriptEntry(String language, String languagename,
|
||||
String location, Map<String,String> languagedepprops) {
|
||||
this( language, languagename, location );
|
||||
String location, Map<String, String> languagedepprops) {
|
||||
this(language, languagename, location);
|
||||
this.languagedepprops = languagedepprops;
|
||||
}
|
||||
|
||||
public ScriptEntry(String language, String languagename,
|
||||
String location, Map<String,String> languagedepprops,
|
||||
String location, Map<String, String> languagedepprops,
|
||||
String description) {
|
||||
this( language, languagename, location );
|
||||
this(language, languagename, location);
|
||||
this.languagedepprops = languagedepprops;
|
||||
this.description = description;
|
||||
}
|
||||
@@ -77,14 +76,13 @@ public class ScriptEntry implements Cloneable {
|
||||
|
||||
public boolean equals(ScriptEntry other) {
|
||||
return language.equals(other.getLanguage()) &&
|
||||
languagename.equals(other.getLanguageName()) &&
|
||||
logicalname.equals(other.getLogicalName()) &&
|
||||
languagedepprops.equals(other.getLanguageProperties()) &&
|
||||
location.equals(other.getLocation());
|
||||
languagename.equals(other.getLanguageName()) &&
|
||||
logicalname.equals(other.getLogicalName()) &&
|
||||
languagedepprops.equals(other.getLanguageProperties()) &&
|
||||
location.equals(other.getLocation());
|
||||
}
|
||||
|
||||
public Map<String,String> getLanguageProperties()
|
||||
{
|
||||
public Map<String, String> getLanguageProperties() {
|
||||
return languagedepprops;
|
||||
}
|
||||
|
||||
@@ -114,6 +112,7 @@ public class ScriptEntry implements Cloneable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "\nLogicalName = " + logicalname + "\nLanguageName = " + languagename + "\nLocation = " + location + "\nLanguaguageProperties = " + languagedepprops;
|
||||
return "\nLogicalName = " + logicalname + "\nLanguageName = " + languagename +
|
||||
"\nLocation = " + location + "\nLanguaguageProperties = " + languagedepprops;
|
||||
}
|
||||
}
|
||||
|
@@ -42,49 +42,47 @@ public class ScriptMetaData extends ScriptEntry {
|
||||
private Parcel parent;
|
||||
|
||||
|
||||
public ScriptMetaData( Parcel parent, ScriptEntry entry,
|
||||
String source )
|
||||
{
|
||||
super( entry );
|
||||
public ScriptMetaData(Parcel parent, ScriptEntry entry,
|
||||
String source) {
|
||||
super(entry);
|
||||
this.parent = parent;
|
||||
if ( source != null )
|
||||
{
|
||||
|
||||
if (source != null) {
|
||||
this.hasSource = true;
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean hasSource()
|
||||
{
|
||||
public boolean hasSource() {
|
||||
return hasSource;
|
||||
}
|
||||
|
||||
public String getSource() {
|
||||
return ( source !=null && hasSource ) ? source : null;
|
||||
return (source != null && hasSource) ? source : null;
|
||||
}
|
||||
|
||||
public byte[] getSourceBytes() {
|
||||
return ( source !=null && hasSource ) ? source.getBytes() : null;
|
||||
return (source != null && hasSource) ? source.getBytes() : null;
|
||||
}
|
||||
|
||||
public boolean equals(ScriptMetaData other) {
|
||||
return super.equals(other) && hasSource == other.hasSource();
|
||||
}
|
||||
|
||||
public String getScriptFullURL()
|
||||
{
|
||||
String url = "vnd.sun.star.script:" + parent.getName() + "." + getLanguageName() +
|
||||
"?" + "language=" + getLanguage() +
|
||||
"&location=" + getParcelLocation();
|
||||
return url;
|
||||
public String getScriptFullURL() {
|
||||
String url = "vnd.sun.star.script:" + parent.getName() + "." + getLanguageName()
|
||||
+
|
||||
"?" + "language=" + getLanguage() +
|
||||
"&location=" + getParcelLocation();
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getShortFormScriptURL()
|
||||
{
|
||||
String url = "vnd.sun.star.script:" + parent.getName() + "." + getLanguageName() +
|
||||
"?" + "language=" + getLanguage() +
|
||||
"&location=" + getLocationPlaceHolder();
|
||||
public String getShortFormScriptURL() {
|
||||
String url = "vnd.sun.star.script:" + parent.getName() + "." + getLanguageName()
|
||||
+
|
||||
"?" + "language=" + getLanguage() +
|
||||
"&location=" + getLocationPlaceHolder();
|
||||
return url;
|
||||
}
|
||||
|
||||
@@ -111,78 +109,60 @@ public class ScriptMetaData extends ScriptEntry {
|
||||
private static final String UNO_SHARED_PACKAGES2 =
|
||||
SHARE + "/uno_packages";
|
||||
|
||||
public static String getLocationPlaceHolder(String url, String pkgname)
|
||||
{
|
||||
public static String getLocationPlaceHolder(String url, String pkgname) {
|
||||
String result = "Unknown";
|
||||
|
||||
if ( url.contains(UNO_USER_PACKAGES1) ||
|
||||
url.contains(UNO_USER_PACKAGES2) )
|
||||
{
|
||||
result = PathUtils.make_url( "user:uno_packages", pkgname );
|
||||
}
|
||||
else if ( url.contains(UNO_SHARED_PACKAGES1) ||
|
||||
url.contains(UNO_SHARED_PACKAGES2) )
|
||||
{
|
||||
result = PathUtils.make_url( "share:uno_packages", pkgname );
|
||||
}
|
||||
else if ( url.indexOf(SHARE) == 0 )
|
||||
{
|
||||
if (url.contains(UNO_USER_PACKAGES1) ||
|
||||
url.contains(UNO_USER_PACKAGES2)) {
|
||||
result = PathUtils.make_url("user:uno_packages", pkgname);
|
||||
} else if (url.contains(UNO_SHARED_PACKAGES1) ||
|
||||
url.contains(UNO_SHARED_PACKAGES2)) {
|
||||
result = PathUtils.make_url("share:uno_packages", pkgname);
|
||||
} else if (url.indexOf(SHARE) == 0) {
|
||||
result = "share";
|
||||
}
|
||||
else if ( url.indexOf(USER) == 0 )
|
||||
{
|
||||
} else if (url.indexOf(USER) == 0) {
|
||||
result = "user";
|
||||
}
|
||||
else if ( url.indexOf("vnd.sun.star.tdoc:") == 0 )
|
||||
{
|
||||
} else if (url.indexOf("vnd.sun.star.tdoc:") == 0) {
|
||||
result = "document";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getLocationPlaceHolder()
|
||||
{
|
||||
public String getLocationPlaceHolder() {
|
||||
String placeHolder = "Unknown";
|
||||
String pathToParcel = parent.getPathToParcel();
|
||||
|
||||
if ( pathToParcel.contains(UNO_USER_PACKAGES1) ||
|
||||
pathToParcel.contains(UNO_USER_PACKAGES2) )
|
||||
{
|
||||
if (pathToParcel.contains(UNO_USER_PACKAGES1) ||
|
||||
pathToParcel.contains(UNO_USER_PACKAGES2)) {
|
||||
// it's a package
|
||||
placeHolder = "user:uno_packages";
|
||||
String unoPkg = parent.parent.getName();
|
||||
if ( unoPkg != null )
|
||||
{
|
||||
placeHolder = PathUtils.make_url( placeHolder, unoPkg );
|
||||
|
||||
if (unoPkg != null) {
|
||||
placeHolder = PathUtils.make_url(placeHolder, unoPkg);
|
||||
}
|
||||
}
|
||||
else if ( pathToParcel.contains(UNO_SHARED_PACKAGES1) ||
|
||||
pathToParcel.contains(UNO_SHARED_PACKAGES2) )
|
||||
{
|
||||
} else if (pathToParcel.contains(UNO_SHARED_PACKAGES1) ||
|
||||
pathToParcel.contains(UNO_SHARED_PACKAGES2)) {
|
||||
//its a package
|
||||
placeHolder = "share:uno_packages";
|
||||
String unoPkg = parent.parent.getName();
|
||||
if ( unoPkg != null )
|
||||
{
|
||||
placeHolder = PathUtils.make_url( placeHolder, unoPkg );
|
||||
|
||||
if (unoPkg != null) {
|
||||
placeHolder = PathUtils.make_url(placeHolder, unoPkg);
|
||||
}
|
||||
}
|
||||
else if ( pathToParcel.indexOf(SHARE) == 0 )
|
||||
{
|
||||
} else if (pathToParcel.indexOf(SHARE) == 0) {
|
||||
placeHolder = "share";
|
||||
}
|
||||
else if ( pathToParcel.indexOf(USER) == 0 )
|
||||
{
|
||||
} else if (pathToParcel.indexOf(USER) == 0) {
|
||||
placeHolder = "user";
|
||||
}
|
||||
else if ( pathToParcel.indexOf("vnd.sun.star.tdoc:") == 0 )
|
||||
{
|
||||
} else if (pathToParcel.indexOf("vnd.sun.star.tdoc:") == 0) {
|
||||
placeHolder = "document";
|
||||
}
|
||||
|
||||
// TODO handling document packages ??? not really sure of package url
|
||||
/* else
|
||||
{
|
||||
} */
|
||||
/* else
|
||||
{
|
||||
} */
|
||||
return placeHolder;
|
||||
}
|
||||
|
||||
@@ -193,76 +173,69 @@ public class ScriptMetaData extends ScriptEntry {
|
||||
// Also if it is to remain needs to be renamed to getParcelLocationURL
|
||||
|
||||
// return URL string to parcel
|
||||
public String getParcelLocation()
|
||||
{
|
||||
public String getParcelLocation() {
|
||||
return parent.getPathToParcel();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "\nParcelLocation = " + getParcelLocation() + "\nLocationPlaceHolder = " + locationPlaceHolder + super.toString();
|
||||
public String toString() {
|
||||
return "\nParcelLocation = " + getParcelLocation() + "\nLocationPlaceHolder = "
|
||||
+ locationPlaceHolder + super.toString();
|
||||
}
|
||||
|
||||
public URL[] getClassPath()
|
||||
{
|
||||
try
|
||||
{
|
||||
String classpath = getLanguageProperties().get("classpath");
|
||||
public URL[] getClassPath() {
|
||||
try {
|
||||
String classpath = getLanguageProperties().get("classpath");
|
||||
|
||||
if ( classpath == null )
|
||||
{
|
||||
classpath = "";
|
||||
}
|
||||
|
||||
String parcelPath = getParcelLocation();
|
||||
// make sure path ends with /
|
||||
if ( !parcelPath.endsWith("/") )
|
||||
{
|
||||
parcelPath += "/";
|
||||
}
|
||||
|
||||
// replace \ with /
|
||||
parcelPath = parcelPath.replace( '\\', '/' );
|
||||
|
||||
ArrayList<URL> classPathVec = new ArrayList<URL>();
|
||||
StringTokenizer stk = new StringTokenizer(classpath, ":");
|
||||
while ( stk.hasMoreElements() )
|
||||
{
|
||||
String relativeClasspath = stk.nextToken();
|
||||
String pathToProcess = PathUtils.make_url( parcelPath, relativeClasspath);
|
||||
URL url = createURL( pathToProcess );
|
||||
if ( url != null )
|
||||
{
|
||||
classPathVec.add ( url );
|
||||
if (classpath == null) {
|
||||
classpath = "";
|
||||
}
|
||||
|
||||
}
|
||||
if ( classPathVec.size() == 0)
|
||||
{
|
||||
URL url = createURL( parcelPath );
|
||||
if ( url != null )
|
||||
{
|
||||
classPathVec.add(url);
|
||||
String parcelPath = getParcelLocation();
|
||||
|
||||
// make sure path ends with /
|
||||
if (!parcelPath.endsWith("/")) {
|
||||
parcelPath += "/";
|
||||
}
|
||||
|
||||
// replace \ with /
|
||||
parcelPath = parcelPath.replace('\\', '/');
|
||||
|
||||
ArrayList<URL> classPathVec = new ArrayList<URL>();
|
||||
StringTokenizer stk = new StringTokenizer(classpath, ":");
|
||||
|
||||
while (stk.hasMoreElements()) {
|
||||
String relativeClasspath = stk.nextToken();
|
||||
String pathToProcess = PathUtils.make_url(parcelPath, relativeClasspath);
|
||||
URL url = createURL(pathToProcess);
|
||||
|
||||
if (url != null) {
|
||||
classPathVec.add(url);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (classPathVec.size() == 0) {
|
||||
URL url = createURL(parcelPath);
|
||||
|
||||
if (url != null) {
|
||||
classPathVec.add(url);
|
||||
}
|
||||
}
|
||||
|
||||
return classPathVec.toArray(new URL[classPathVec.size()]);
|
||||
} catch (Exception e) {
|
||||
LogUtils.DEBUG("Failed to build class path " + e.toString());
|
||||
LogUtils.DEBUG(LogUtils.getTrace(e));
|
||||
return new URL[0];
|
||||
}
|
||||
|
||||
return classPathVec.toArray( new URL[classPathVec.size()]);
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
LogUtils.DEBUG("Failed to build class path " + e.toString() );
|
||||
LogUtils.DEBUG( LogUtils.getTrace( e ) );
|
||||
return new URL[0];
|
||||
}
|
||||
|
||||
}
|
||||
private URL createURL( String path ) throws java.net.MalformedURLException
|
||||
{
|
||||
private URL createURL(String path) throws java.net.MalformedURLException {
|
||||
int indexOfColon = path.indexOf(':');
|
||||
String scheme = path.substring( 0, indexOfColon );
|
||||
UCBStreamHandler handler = new UCBStreamHandler( scheme, parent.m_xSFA);
|
||||
String scheme = path.substring(0, indexOfColon);
|
||||
UCBStreamHandler handler = new UCBStreamHandler(scheme, parent.m_xSFA);
|
||||
|
||||
path += UCBStreamHandler.separator;
|
||||
return new URL(null, path, handler);
|
||||
@@ -270,87 +243,81 @@ public class ScriptMetaData extends ScriptEntry {
|
||||
|
||||
// TODO should decide whether this should throw or not
|
||||
// decide whether it should be public or protected ( final ? )
|
||||
public void loadSource()
|
||||
{
|
||||
try
|
||||
{
|
||||
URL sourceUrl = getSourceURL();
|
||||
LogUtils.DEBUG("** In load source BUT not loading yet for " + sourceUrl );
|
||||
public void loadSource() {
|
||||
try {
|
||||
URL sourceUrl = getSourceURL();
|
||||
LogUtils.DEBUG("** In load source BUT not loading yet for " + sourceUrl);
|
||||
|
||||
if ( sourceUrl != null )
|
||||
{
|
||||
StringBuilder buf = new StringBuilder();
|
||||
InputStream in = sourceUrl.openStream();
|
||||
if (sourceUrl != null) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
InputStream in = sourceUrl.openStream();
|
||||
|
||||
byte[] contents = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(contents, 0, 1024)) != -1) {
|
||||
buf.append(new String(contents, 0, len));
|
||||
}
|
||||
byte[] contents = new byte[1024];
|
||||
int len;
|
||||
|
||||
try {
|
||||
in.close();
|
||||
}
|
||||
catch (java.io.IOException ignore ) {
|
||||
LogUtils.DEBUG("** Failed to read scriot from url " + ignore.toString() );
|
||||
}
|
||||
|
||||
source = buf.toString();
|
||||
hasSource = true;
|
||||
while ((len = in.read(contents, 0, 1024)) != -1) {
|
||||
buf.append(new String(contents, 0, len));
|
||||
}
|
||||
}
|
||||
catch (java.io.IOException e) {
|
||||
LogUtils.DEBUG("** Failed to read scriot from url " + e.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
in.close();
|
||||
} catch (java.io.IOException ignore) {
|
||||
LogUtils.DEBUG("** Failed to read scriot from url " + ignore.toString());
|
||||
}
|
||||
|
||||
source = buf.toString();
|
||||
hasSource = true;
|
||||
}
|
||||
} catch (java.io.IOException e) {
|
||||
LogUtils.DEBUG("** Failed to read scriot from url " + e.toString());
|
||||
}
|
||||
protected boolean writeSourceFile()
|
||||
{
|
||||
|
||||
}
|
||||
protected boolean writeSourceFile() {
|
||||
String sourceFilePath = parent.getPathToParcel() + "/" + getLanguageName();
|
||||
boolean result = false;
|
||||
try
|
||||
{
|
||||
XSimpleFileAccess2 xSFA2 = UnoRuntime.queryInterface( XSimpleFileAccess2.class,
|
||||
parent.m_xSFA );
|
||||
if ( xSFA2 != null )
|
||||
{
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream( getSourceBytes() );
|
||||
XInputStreamImpl xis = new XInputStreamImpl( bis );
|
||||
xSFA2.writeFile( sourceFilePath, xis );
|
||||
|
||||
try {
|
||||
XSimpleFileAccess2 xSFA2 = UnoRuntime.queryInterface(XSimpleFileAccess2.class,
|
||||
parent.m_xSFA);
|
||||
|
||||
if (xSFA2 != null) {
|
||||
ByteArrayInputStream bis = new ByteArrayInputStream(getSourceBytes());
|
||||
XInputStreamImpl xis = new XInputStreamImpl(bis);
|
||||
xSFA2.writeFile(sourceFilePath, xis);
|
||||
xis.closeInput();
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
// TODO re-examine exception processing should probably throw
|
||||
// exceptions back to caller
|
||||
catch ( Exception ignore )
|
||||
catch (Exception ignore)
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
protected boolean removeSourceFile()
|
||||
{
|
||||
protected boolean removeSourceFile() {
|
||||
String parcelLocation = parent.getPathToParcel();
|
||||
String sourceFilePath = parcelLocation + "/" + getLanguageName();
|
||||
boolean result = false;
|
||||
try
|
||||
{
|
||||
parent.m_xSFA.kill( sourceFilePath );
|
||||
|
||||
try {
|
||||
parent.m_xSFA.kill(sourceFilePath);
|
||||
result = true;
|
||||
}
|
||||
// TODO reexamine exception handling
|
||||
catch ( Exception e )
|
||||
{
|
||||
catch (Exception e) {
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public URL getSourceURL() throws java.net.MalformedURLException
|
||||
{
|
||||
public URL getSourceURL() throws java.net.MalformedURLException {
|
||||
String sUrl = getParcelLocation();
|
||||
sUrl = PathUtils.make_url( sUrl, getLanguageName() );
|
||||
LogUtils.DEBUG("Creating script url for " + sUrl );
|
||||
return createURL( sUrl );
|
||||
sUrl = PathUtils.make_url(sUrl, getLanguageName());
|
||||
LogUtils.DEBUG("Creating script url for " + sUrl);
|
||||
return createURL(sUrl);
|
||||
}
|
||||
}
|
||||
|
@@ -33,136 +33,128 @@ import com.sun.star.io.XOutputStream;
|
||||
import com.sun.star.io.XTruncate;
|
||||
import com.sun.star.deployment.XPackage;
|
||||
|
||||
public class UnoPkgContainer extends ParcelContainer
|
||||
{
|
||||
public class UnoPkgContainer extends ParcelContainer {
|
||||
|
||||
private Map<String,ParcelContainer> registeredPackages = new HashMap<String,ParcelContainer>();
|
||||
private Map<String, ParcelContainer> registeredPackages = new
|
||||
HashMap<String, ParcelContainer>();
|
||||
private String extensionDb;
|
||||
private String extensionRepository;
|
||||
|
||||
public UnoPkgContainer( XComponentContext xCtx, String locationURL,
|
||||
String _extensionDb, String _extensionRepository, String language ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException
|
||||
{
|
||||
super( xCtx, locationURL, language, false );
|
||||
public UnoPkgContainer(XComponentContext xCtx, String locationURL,
|
||||
String _extensionDb, String _extensionRepository,
|
||||
String language) throws com.sun.star.lang.IllegalArgumentException,
|
||||
com.sun.star.lang.WrappedTargetException {
|
||||
super(xCtx, locationURL, language, false);
|
||||
extensionDb = _extensionDb;
|
||||
extensionRepository = _extensionRepository;
|
||||
init();
|
||||
}
|
||||
|
||||
// gets the ParcelContainer for persisted uno packages
|
||||
public ParcelContainer getRegisteredUnoPkgContainer( String url )
|
||||
{
|
||||
if (!url.endsWith("/"))
|
||||
{
|
||||
public ParcelContainer getRegisteredUnoPkgContainer(String url) {
|
||||
if (!url.endsWith("/")) {
|
||||
url += "/";
|
||||
}
|
||||
|
||||
LogUtils.DEBUG("** getRegisterPackage ctx = " + containerUrl );
|
||||
LogUtils.DEBUG("** getRegisterPackage for uri " + url );
|
||||
LogUtils.DEBUG("** getRegisterPackage for langugage " + language );
|
||||
ParcelContainer result = registeredPackages.get( url );
|
||||
LogUtils.DEBUG("getRegisterPackage result is " + result );
|
||||
LogUtils.DEBUG("** getRegisterPackage ctx = " + containerUrl);
|
||||
LogUtils.DEBUG("** getRegisterPackage for uri " + url);
|
||||
LogUtils.DEBUG("** getRegisterPackage for langugage " + language);
|
||||
ParcelContainer result = registeredPackages.get(url);
|
||||
LogUtils.DEBUG("getRegisterPackage result is " + result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean hasRegisteredUnoPkgContainer( String url ) {
|
||||
return getRegisteredUnoPkgContainer( url ) != null;
|
||||
public boolean hasRegisteredUnoPkgContainer(String url) {
|
||||
return getRegisteredUnoPkgContainer(url) != null;
|
||||
}
|
||||
|
||||
private void registerPackageContainer( String url, ParcelContainer c )
|
||||
{
|
||||
if (!url.endsWith("/"))
|
||||
{
|
||||
private void registerPackageContainer(String url, ParcelContainer c) {
|
||||
if (!url.endsWith("/")) {
|
||||
url += "/";
|
||||
}
|
||||
|
||||
LogUtils.DEBUG("RegisterPackage ctx = " + containerUrl );
|
||||
LogUtils.DEBUG("RegisterPackage language = " + language );
|
||||
LogUtils.DEBUG("RegisterPackage " + c + " for url " + url );
|
||||
registeredPackages.put( url, c );
|
||||
LogUtils.DEBUG("RegisterPackage ctx = " + containerUrl);
|
||||
LogUtils.DEBUG("RegisterPackage language = " + language);
|
||||
LogUtils.DEBUG("RegisterPackage " + c + " for url " + url);
|
||||
registeredPackages.put(url, c);
|
||||
}
|
||||
|
||||
public void deRegisterPackageContainer( String url )
|
||||
{
|
||||
if (!url.endsWith("/"))
|
||||
{
|
||||
public void deRegisterPackageContainer(String url) {
|
||||
if (!url.endsWith("/")) {
|
||||
url += "/";
|
||||
}
|
||||
|
||||
LogUtils.DEBUG("In deRegisterPackageContainer for " + url );
|
||||
if ( hasRegisteredUnoPkgContainer( url ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
LogUtils.DEBUG("In deRegisterPackageContainer for " + url);
|
||||
|
||||
if (hasRegisteredUnoPkgContainer(url)) {
|
||||
try {
|
||||
DeployedUnoPackagesDB db = getUnoPackagesDB();
|
||||
if ( db != null )
|
||||
{
|
||||
if ( db.removePackage( language, url ) )
|
||||
{
|
||||
writeUnoPackageDB( db );
|
||||
ParcelContainer container = registeredPackages.get( url );
|
||||
if ( !container.hasElements() )
|
||||
{
|
||||
// When all libraries within a package bundle
|
||||
// ( for this language ) are removed also
|
||||
// remove the container from its parent
|
||||
// Otherwise, a container ( with no containees )
|
||||
// representing the uno package bundle will
|
||||
// still exist and so will get displayed
|
||||
if ( container.parent() != null )
|
||||
{
|
||||
container.parent().removeChildContainer( container );
|
||||
}
|
||||
}
|
||||
registeredPackages.remove( url );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//TODO revisit exception handling and exception here
|
||||
//means something very wrong
|
||||
LogUtils.DEBUG("***** deRegisterPackageContainer() got exception " + e );
|
||||
}
|
||||
|
||||
if (db != null) {
|
||||
if (db.removePackage(language, url)) {
|
||||
writeUnoPackageDB(db);
|
||||
ParcelContainer container = registeredPackages.get(url);
|
||||
|
||||
if (!container.hasElements()) {
|
||||
// When all libraries within a package bundle
|
||||
// ( for this language ) are removed also
|
||||
// remove the container from its parent
|
||||
// Otherwise, a container ( with no containees )
|
||||
// representing the uno package bundle will
|
||||
// still exist and so will get displayed
|
||||
if (container.parent() != null) {
|
||||
container.parent().removeChildContainer(container);
|
||||
}
|
||||
}
|
||||
|
||||
registeredPackages.remove(url);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//TODO revisit exception handling and exception here
|
||||
//means something very wrong
|
||||
LogUtils.DEBUG("***** deRegisterPackageContainer() got exception " + e);
|
||||
}
|
||||
}
|
||||
LogUtils.DEBUG("Leaving deRegisterPackageContainer for " + url );
|
||||
|
||||
LogUtils.DEBUG("Leaving deRegisterPackageContainer for " + url);
|
||||
}
|
||||
|
||||
private void init() throws com.sun.star.lang.IllegalArgumentException
|
||||
{
|
||||
LogUtils.DEBUG("getting container for " + containerUrl );
|
||||
try
|
||||
{
|
||||
private void init() throws com.sun.star.lang.IllegalArgumentException {
|
||||
LogUtils.DEBUG("getting container for " + containerUrl);
|
||||
|
||||
try {
|
||||
DeployedUnoPackagesDB db = getUnoPackagesDB();
|
||||
if ( db != null )
|
||||
{
|
||||
String[] packages = db.getDeployedPackages( language );
|
||||
|
||||
if (db != null) {
|
||||
String[] packages = db.getDeployedPackages(language);
|
||||
|
||||
for (String thepackage : packages) {
|
||||
try {
|
||||
processUnoPackage(thepackage, language);
|
||||
} catch (com.sun.star.lang.IllegalArgumentException ila) {
|
||||
LogUtils.DEBUG("Failed to process " + thepackage + " for " + language);
|
||||
LogUtils.DEBUG(" Reason: " + ila );
|
||||
LogUtils.DEBUG(" Reason: " + ila);
|
||||
} catch (Exception e) {
|
||||
// TODO proper exception or do we wish
|
||||
// to ignore errors here
|
||||
LogUtils.DEBUG("Something very wrong!!!!!");
|
||||
LogUtils.DEBUG("Failed to process " + thepackage + " for " + language);
|
||||
LogUtils.DEBUG(" Reason: " + e );
|
||||
LogUtils.DEBUG(" Reason: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( com.sun.star.lang.WrappedTargetException e )
|
||||
{
|
||||
} catch (com.sun.star.lang.WrappedTargetException e) {
|
||||
// no deployed packages
|
||||
LogUtils.DEBUG("No deployed uno-packages for " + containerUrl );
|
||||
LogUtils.DEBUG("No deployed uno-packages for " + containerUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ScriptMetaData findScript( ParsedScriptUri psu ) throws com.sun.star.container.NoSuchElementException, com.sun.star.lang.WrappedTargetException
|
||||
public ScriptMetaData findScript(ParsedScriptUri psu) throws
|
||||
com.sun.star.container.NoSuchElementException,
|
||||
com.sun.star.lang.WrappedTargetException
|
||||
|
||||
{
|
||||
ScriptMetaData scriptData = null;
|
||||
@@ -172,70 +164,59 @@ public class UnoPkgContainer extends ParcelContainer
|
||||
String location = psu.location;
|
||||
|
||||
LogUtils.DEBUG("*** UnoPkgContainer.findScript() ***" +
|
||||
"\ncontainerUrl = " + containerUrl +
|
||||
"\nfunction = " + functionName +
|
||||
"\nlocation = " + location +
|
||||
"\nparcel = " + parcelName );
|
||||
"\ncontainerUrl = " + containerUrl +
|
||||
"\nfunction = " + functionName +
|
||||
"\nlocation = " + location +
|
||||
"\nparcel = " + parcelName);
|
||||
|
||||
ParcelContainer pc = getChildContainer( location );
|
||||
ParcelContainer pc = getChildContainer(location);
|
||||
|
||||
if ( pc == null )
|
||||
{
|
||||
throw new com.sun.star.lang.WrappedTargetException( "Failed to resolve script " , null, new com.sun.star.lang.IllegalArgumentException( "Cannot resolve script location for script = " + functionName ) );
|
||||
if (pc == null) {
|
||||
throw new com.sun.star.lang.WrappedTargetException("Failed to resolve script " ,
|
||||
null, new com.sun.star.lang.IllegalArgumentException("Cannot resolve script location for script = "
|
||||
+ functionName));
|
||||
}
|
||||
|
||||
return pc.findScript( psu );
|
||||
return pc.findScript(psu);
|
||||
}
|
||||
|
||||
private DeployedUnoPackagesDB getUnoPackagesDB() throws com.sun.star.lang.WrappedTargetException
|
||||
{
|
||||
private DeployedUnoPackagesDB getUnoPackagesDB() throws
|
||||
com.sun.star.lang.WrappedTargetException {
|
||||
InputStream is = null;
|
||||
DeployedUnoPackagesDB dp = null;
|
||||
try
|
||||
{
|
||||
String packagesUrl = PathUtils.make_url( extensionDb, "/Scripts/" + extensionRepository + "-extension-desc.xml" );
|
||||
LogUtils.DEBUG("getUnoPackagesDB() looking for existing db in " + packagesUrl );
|
||||
if ( m_xSFA.exists( packagesUrl ) )
|
||||
{
|
||||
if ( packagesUrl.startsWith( "vnd.sun.star.tdoc" ) )
|
||||
{
|
||||
|
||||
try {
|
||||
String packagesUrl = PathUtils.make_url(extensionDb,
|
||||
"/Scripts/" + extensionRepository + "-extension-desc.xml");
|
||||
LogUtils.DEBUG("getUnoPackagesDB() looking for existing db in " + packagesUrl);
|
||||
|
||||
if (m_xSFA.exists(packagesUrl)) {
|
||||
if (packagesUrl.startsWith("vnd.sun.star.tdoc")) {
|
||||
// handles using XStorage directly
|
||||
throw new com.sun.star.lang.WrappedTargetException("Can't handle documents yet");
|
||||
}
|
||||
|
||||
is = new XInputStreamWrapper( m_xSFA.openFileRead( packagesUrl ) );
|
||||
dp = new DeployedUnoPackagesDB( is );
|
||||
try
|
||||
{
|
||||
is = new XInputStreamWrapper(m_xSFA.openFileRead(packagesUrl));
|
||||
dp = new DeployedUnoPackagesDB(is);
|
||||
|
||||
try {
|
||||
is.close();
|
||||
is = null;
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
catch ( Exception ignore )
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
LogUtils.DEBUG("getUnoPackagesDB() " + packagesUrl + " does not exist");
|
||||
}
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
LogUtils.DEBUG("getUnoPackagesDB() caught Exception: " + e );
|
||||
LogUtils.DEBUG( LogUtils.getTrace( e ) );
|
||||
} catch (Exception e) {
|
||||
LogUtils.DEBUG("getUnoPackagesDB() caught Exception: " + e);
|
||||
LogUtils.DEBUG(LogUtils.getTrace(e));
|
||||
throw new com.sun.star.lang.WrappedTargetException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ( is != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
is = null;
|
||||
}
|
||||
catch ( Exception ignore )
|
||||
{
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -243,160 +224,151 @@ public class UnoPkgContainer extends ParcelContainer
|
||||
return dp;
|
||||
}
|
||||
|
||||
private void writeUnoPackageDB( DeployedUnoPackagesDB dp ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException
|
||||
{
|
||||
private void writeUnoPackageDB(DeployedUnoPackagesDB dp) throws
|
||||
com.sun.star.lang.IllegalArgumentException,
|
||||
com.sun.star.lang.WrappedTargetException {
|
||||
LogUtils.DEBUG("In writeUnoPackageDB() ");
|
||||
|
||||
XOutputStream xos = null;
|
||||
OutputStream os = null;
|
||||
try
|
||||
{
|
||||
String packagesUrl = PathUtils.make_url( extensionDb, "/Scripts/" + extensionRepository + "-extension-desc.xml" );
|
||||
xos = m_xSFA.openFileWrite( packagesUrl );
|
||||
XTruncate xTrc = UnoRuntime.queryInterface( XTruncate.class, xos );
|
||||
if ( xTrc != null )
|
||||
{
|
||||
LogUtils.DEBUG("In writeUnoPackageDB() Truncating...." );
|
||||
|
||||
try {
|
||||
String packagesUrl = PathUtils.make_url(extensionDb,
|
||||
"/Scripts/" + extensionRepository + "-extension-desc.xml");
|
||||
xos = m_xSFA.openFileWrite(packagesUrl);
|
||||
XTruncate xTrc = UnoRuntime.queryInterface(XTruncate.class, xos);
|
||||
|
||||
if (xTrc != null) {
|
||||
LogUtils.DEBUG("In writeUnoPackageDB() Truncating....");
|
||||
xTrc.truncate();
|
||||
} else {
|
||||
LogUtils.DEBUG("In writeUnoPackageDB() CAN'T Truncate....");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogUtils.DEBUG("In writeUnoPackageDB() CAN'T Truncate...." );
|
||||
}
|
||||
os = new XOutputStreamWrapper( xos );
|
||||
dp.write( os );
|
||||
try
|
||||
{
|
||||
|
||||
os = new XOutputStreamWrapper(xos);
|
||||
dp.write(os);
|
||||
|
||||
try {
|
||||
os.close(); // will close xos
|
||||
os = null;
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
catch( Exception ignore )
|
||||
{
|
||||
}
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
LogUtils.DEBUG("In writeUnoPackageDB() Exception: " + e );
|
||||
} catch (Exception e) {
|
||||
LogUtils.DEBUG("In writeUnoPackageDB() Exception: " + e);
|
||||
throw new com.sun.star.lang.WrappedTargetException(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if ( os != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
} finally {
|
||||
if (os != null) {
|
||||
try {
|
||||
os.close(); // will close xos
|
||||
os = null;
|
||||
}
|
||||
catch ( Exception ignore )
|
||||
{
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void processUnoPackage( XPackage dPackage, String language ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException, com.sun.star.container.ElementExistException
|
||||
{
|
||||
LogUtils.DEBUG("** in processUnoPackage " );
|
||||
public void processUnoPackage(XPackage dPackage,
|
||||
String language) throws com.sun.star.lang.IllegalArgumentException,
|
||||
com.sun.star.lang.WrappedTargetException,
|
||||
com.sun.star.container.ElementExistException {
|
||||
LogUtils.DEBUG("** in processUnoPackage ");
|
||||
String uri = dPackage.getURL();
|
||||
|
||||
if ( !uri.endsWith( "/" ) )
|
||||
{
|
||||
if (!uri.endsWith("/")) {
|
||||
uri += "/";
|
||||
}
|
||||
|
||||
LogUtils.DEBUG("** processUnoPackage getURL() -> " + uri );
|
||||
LogUtils.DEBUG("** processUnoPackage getName() -> " + dPackage.getName() );
|
||||
LogUtils.DEBUG("** processUnoPackage getMediaType() -> " + dPackage.getPackageType().getMediaType() );
|
||||
try
|
||||
{
|
||||
LogUtils.DEBUG("** processUnoPackage getDisplayName() -> " + dPackage.getDisplayName() );
|
||||
}
|
||||
catch (com.sun.star.deployment.ExtensionRemovedException e)
|
||||
{
|
||||
LogUtils.DEBUG("** processUnoPackage getURL() -> " + uri);
|
||||
LogUtils.DEBUG("** processUnoPackage getName() -> " + dPackage.getName());
|
||||
LogUtils.DEBUG("** processUnoPackage getMediaType() -> " +
|
||||
dPackage.getPackageType().getMediaType());
|
||||
|
||||
try {
|
||||
LogUtils.DEBUG("** processUnoPackage getDisplayName() -> " +
|
||||
dPackage.getDisplayName());
|
||||
} catch (com.sun.star.deployment.ExtensionRemovedException e) {
|
||||
throw new com.sun.star.lang.WrappedTargetException(e.getMessage(), this, e);
|
||||
}
|
||||
|
||||
processUnoPackage( uri, language );
|
||||
processUnoPackage(uri, language);
|
||||
|
||||
DeployedUnoPackagesDB db = getUnoPackagesDB();
|
||||
if ( db == null )
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (db == null) {
|
||||
try {
|
||||
db = new DeployedUnoPackagesDB();
|
||||
}
|
||||
catch ( java.io.IOException ioe )
|
||||
{
|
||||
} catch (java.io.IOException ioe) {
|
||||
throw new com.sun.star.lang.WrappedTargetException(ioe);
|
||||
}
|
||||
}
|
||||
db.addPackage( language, uri );
|
||||
writeUnoPackageDB( db );
|
||||
|
||||
db.addPackage(language, uri);
|
||||
writeUnoPackageDB(db);
|
||||
}
|
||||
|
||||
private void processUnoPackage( String uri, String language ) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.lang.WrappedTargetException, com.sun.star.container.ElementExistException
|
||||
{
|
||||
if ( hasRegisteredUnoPkgContainer( uri ) )
|
||||
{
|
||||
throw new com.sun.star.container.ElementExistException( "Already a registered uno package " + uri + " for language " + language );
|
||||
private void processUnoPackage(String uri,
|
||||
String language) throws com.sun.star.lang.IllegalArgumentException,
|
||||
com.sun.star.lang.WrappedTargetException,
|
||||
com.sun.star.container.ElementExistException {
|
||||
if (hasRegisteredUnoPkgContainer(uri)) {
|
||||
throw new com.sun.star.container.ElementExistException("Already a registered uno package "
|
||||
+ uri + " for language " + language);
|
||||
}
|
||||
LogUtils.DEBUG("processUnoPackage - URL = " + uri );
|
||||
|
||||
LogUtils.DEBUG("processUnoPackage - URL = " + uri);
|
||||
LogUtils.DEBUG("processUnoPackage - script library package");
|
||||
String parentUrl = uri;
|
||||
|
||||
if ( uri.contains("%2Funo_packages%2F") ||
|
||||
uri.contains("/uno_packages/") ||
|
||||
uri.contains("$UNO_USER_PACKAGES_CACHE/") ||
|
||||
uri.contains("$UNO_SHARED_PACKAGES_CACHE/") ||
|
||||
uri.contains("$BUNDLED_EXTENSIONS/") )
|
||||
{
|
||||
if (uri.contains("%2Funo_packages%2F") ||
|
||||
uri.contains("/uno_packages/") ||
|
||||
uri.contains("$UNO_USER_PACKAGES_CACHE/") ||
|
||||
uri.contains("$UNO_SHARED_PACKAGES_CACHE/") ||
|
||||
uri.contains("$BUNDLED_EXTENSIONS/")) {
|
||||
//its in a bundle need to determine the uno-package file its in
|
||||
LogUtils.DEBUG("processUnoPackage - is part of a uno bundle");
|
||||
|
||||
int index = uri.lastIndexOf('/');
|
||||
if ( uri.endsWith("/") )
|
||||
{
|
||||
uri = uri.substring( 0, index );
|
||||
|
||||
if (uri.endsWith("/")) {
|
||||
uri = uri.substring(0, index);
|
||||
index = uri.lastIndexOf('/');
|
||||
}
|
||||
|
||||
if ( index > -1 )
|
||||
{
|
||||
parentUrl = uri.substring( 0, index );
|
||||
if (index > -1) {
|
||||
parentUrl = uri.substring(0, index);
|
||||
LogUtils.DEBUG("processUnoPackage - composition is contained in " + parentUrl);
|
||||
}
|
||||
|
||||
ParcelContainer pkgContainer = getChildContainerForURL( parentUrl );
|
||||
if ( pkgContainer == null )
|
||||
{
|
||||
pkgContainer = new ParcelContainer( this, m_xCtx, parentUrl, language, false );
|
||||
if ( pkgContainer.loadParcel( uri ) == null )
|
||||
{
|
||||
throw new com.sun.star.lang.IllegalArgumentException( "Couldn't load script library from composition package " + uri + " for language " + language );
|
||||
ParcelContainer pkgContainer = getChildContainerForURL(parentUrl);
|
||||
|
||||
if (pkgContainer == null) {
|
||||
pkgContainer = new ParcelContainer(this, m_xCtx, parentUrl, language, false);
|
||||
|
||||
if (pkgContainer.loadParcel(uri) == null) {
|
||||
throw new com.sun.star.lang.IllegalArgumentException("Couldn't load script library from composition package "
|
||||
+ uri + " for language " + language);
|
||||
|
||||
}
|
||||
addChildContainer( pkgContainer );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( pkgContainer.loadParcel( uri ) == null )
|
||||
{
|
||||
throw new com.sun.star.lang.IllegalArgumentException( "Couldn't load script library from composition package " + uri + " for language " + language );
|
||||
|
||||
addChildContainer(pkgContainer);
|
||||
} else {
|
||||
if (pkgContainer.loadParcel(uri) == null) {
|
||||
throw new com.sun.star.lang.IllegalArgumentException("Couldn't load script library from composition package "
|
||||
+ uri + " for language " + language);
|
||||
}
|
||||
|
||||
}
|
||||
registerPackageContainer( uri, pkgContainer );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
registerPackageContainer(uri, pkgContainer);
|
||||
} else {
|
||||
// stand-alone library package, e.g. not contained in
|
||||
// an uno package
|
||||
if ( loadParcel( uri ) == null )
|
||||
{
|
||||
throw new com.sun.star.lang.IllegalArgumentException( "Couldn't load script library package " + uri + " for language " + language );
|
||||
if (loadParcel(uri) == null) {
|
||||
throw new com.sun.star.lang.IllegalArgumentException("Couldn't load script library package "
|
||||
+ uri + " for language " + language);
|
||||
}
|
||||
registerPackageContainer( uri, this );
|
||||
|
||||
registerPackageContainer(uri, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -39,6 +39,7 @@ public class XMLParserFactory {
|
||||
public static synchronized XMLParser getParser() {
|
||||
if (parser == null)
|
||||
parser = new DefaultParser();
|
||||
|
||||
return parser;
|
||||
}
|
||||
|
||||
@@ -69,16 +70,14 @@ public class XMLParserFactory {
|
||||
}
|
||||
|
||||
result = builder.parse(is);
|
||||
}
|
||||
catch (SAXParseException spe) {
|
||||
} catch (SAXParseException spe) {
|
||||
throw new IOException(spe.getMessage());
|
||||
}
|
||||
catch (SAXException se) {
|
||||
} catch (SAXException se) {
|
||||
throw new IOException(se.getMessage());
|
||||
}
|
||||
catch (ParserConfigurationException pce) {
|
||||
} catch (ParserConfigurationException pce) {
|
||||
throw new IOException(pce.getMessage());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -97,10 +96,9 @@ public class XMLParserFactory {
|
||||
// these DOM implementations are self writing
|
||||
Method write;
|
||||
write = clazz.getDeclaredMethod("write",
|
||||
new Class[] {OutputStream.class});
|
||||
new Class[] {OutputStream.class});
|
||||
write.invoke(doc, new Object[] {out});
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// try xerces serialize package using introspection
|
||||
ClassLoader cl = this.getClass().getClassLoader();
|
||||
|
||||
@@ -109,16 +107,16 @@ public class XMLParserFactory {
|
||||
|
||||
try {
|
||||
serializerClass = Class.forName(
|
||||
"org.apache.xml.serialize.XMLSerializer", true, cl);
|
||||
"org.apache.xml.serialize.XMLSerializer", true, cl);
|
||||
formatterClass = Class.forName(
|
||||
"org.apache.xml.serialize.OutputFormat", true, cl);
|
||||
"org.apache.xml.serialize.OutputFormat", true, cl);
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
String prefix = "com.sun.org.apache.xml.internal.";
|
||||
|
||||
serializerClass = Class.forName(
|
||||
prefix + "serialize.XMLSerializer" , true, cl);
|
||||
prefix + "serialize.XMLSerializer" , true, cl);
|
||||
formatterClass = Class.forName(
|
||||
prefix + "serialize.OutputFormat", true, cl);
|
||||
prefix + "serialize.OutputFormat", true, cl);
|
||||
}
|
||||
|
||||
Object serializerObject = serializerClass.newInstance();
|
||||
@@ -126,29 +124,29 @@ public class XMLParserFactory {
|
||||
|
||||
// improve output readability using the OutputFormat class
|
||||
Method method = formatterClass.getMethod("setMethod",
|
||||
new Class[] {String.class});
|
||||
new Class[] {String.class});
|
||||
method.invoke(formatterObject, new Object[] {"xml"});
|
||||
method = formatterClass.getMethod("setIndenting",
|
||||
new Class[] {Boolean.TYPE});
|
||||
new Class[] {Boolean.TYPE});
|
||||
method.invoke(formatterObject, new Object[] {Boolean.TRUE});
|
||||
|
||||
// now set up an instance of XMLSerializer with our
|
||||
// OutputStream and serialize our Document
|
||||
method = serializerClass.getMethod("setOutputByteStream",
|
||||
new Class[] {OutputStream.class});
|
||||
new Class[] {OutputStream.class});
|
||||
method.invoke(serializerObject, new Object[] {out});
|
||||
method = serializerClass.getMethod("setOutputFormat",
|
||||
new Class[] {formatterClass});
|
||||
new Class[] {formatterClass});
|
||||
method.invoke(serializerObject,
|
||||
new Object[] {formatterObject});
|
||||
new Object[] {formatterObject});
|
||||
|
||||
method = serializerClass.getMethod("asDOMSerializer",
|
||||
new Class[0]);
|
||||
new Class[0]);
|
||||
Object impl = method.invoke(serializerObject,
|
||||
new Object[0]);
|
||||
new Object[0]);
|
||||
|
||||
method = impl.getClass().getMethod("serialize",
|
||||
new Class[] {Document.class});
|
||||
new Class[] {Document.class});
|
||||
method.invoke(impl, new Object[] {doc});
|
||||
}
|
||||
} catch (NoSuchMethodException ex) {
|
||||
|
Reference in New Issue
Block a user