/************************************************************** * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * *************************************************************/ package com.sun.star.wiki; import com.sun.star.beans.XPropertySet; import com.sun.star.container.XNameAccess; import com.sun.star.container.XNameContainer; import com.sun.star.container.XNameReplace; import com.sun.star.lang.XSingleServiceFactory; import com.sun.star.uno.AnyConverter; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; import com.sun.star.util.XChangesBatch; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; public class Settings { private XComponentContext m_xContext; private int lastUsedWikiServer = 0; /* Singelton */ private static Settings m_instance; private Vector m_WikiConnections = new Vector(); private Vector m_aWikiDocs = new Vector(); private Settings( XComponentContext ctx ) { m_xContext=ctx; loadConfiguration(); } public static synchronized Settings getSettings( XComponentContext ctx ) { if ( m_instance == null ) m_instance = new Settings( ctx ); // m_instance.loadSettings(); return m_instance; } public void addWikiCon ( Hashtable wikiCon ) { m_WikiConnections.add( wikiCon ); } public Vector getWikiCons() { return m_WikiConnections; } public String getWikiConUrlByNumber( int num ) { String url = ""; if ( num >=0 && num < m_WikiConnections.size() ) { Hashtable ht = ( Hashtable ) m_WikiConnections.get( num ); url = ( String ) ht.get( "Url" ); } return url; } public void addWikiDoc ( Hashtable aWikiDoc ) { String sURL = ( String ) aWikiDoc.get( "CompleteUrl" ); Hashtable aEntry = getDocByCompleteUrl( sURL ); if ( aEntry != null ) { // add doc to the end, even if it has been added before m_aWikiDocs.remove( aEntry ); } else if ( m_aWikiDocs.size() > 10 ) { // if the number of elements has reached maximum the oldest element should be removed m_aWikiDocs.remove( 0 ); } m_aWikiDocs.add( aWikiDoc ); } public Vector getWikiDocs() { return m_aWikiDocs; } public Object[] getWikiDocList( int serverid, int num ) { String wikiserverurl = getWikiConUrlByNumber( serverid ); Vector theDocs = new Vector(); String [] docs = new String[0]; for ( int i=0; i 0 && ( aPassword == null || aPassword.length() == 0 ) ) { String[] pPasswords = Helper.GetPasswordsForURLAndUser( m_xContext, sUrl, sUserName ); if ( pPasswords != null && pPasswords.length > 0 ) ht.put( "Password", pPasswords[0] ); } } catch( Exception e ) { e.printStackTrace(); } break; } } return ht; } public Hashtable getDocByCompleteUrl( String curl ) { Hashtable ht = null; for( int i=0;i 0 ) ht.put( "Username", aUsername ); } } catch( Exception e ) { e.printStackTrace(); } addWikiCon( ht ); } Object oDocs = xAccess.getByName( "RecentDocs" ); XNameAccess xRecentDocs = ( XNameAccess ) UnoRuntime.queryInterface( XNameAccess.class, oDocs ); String [] allDocs = xRecentDocs.getElementNames(); for ( int i=0; i