com.sun.star.container.XNameAccess Java Examples

The following examples show how to use com.sun.star.container.XNameAccess. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApplicationInfo.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * This method can be used to get any info from the application that is available.
 * (Possible paths and keys can be retrieved with the dumpInfo method).
 * Returns the object described by the path and key, or <code>null</code> if not available.
 * 
 * @param path the path to the key information
 * @param key the key to get the value for
 * 
 * @return the object described by the path and key, or <code>null</code> if not available
 * 
 * @throws Exception if retreiving the value fails
 * 
 * @author Markus Krüger
 * @date 18.11.2008
 */
public Object getInfo(String path, String key) throws Exception {
  Object configProviderObject = serviceProvider.createService("com.sun.star.comp.configuration.ConfigurationProvider");
  XMultiServiceFactory xConfigServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class,
      configProviderObject);
  String readConfAccess = "com.sun.star.configuration.ConfigurationAccess";
  PropertyValue[] properties = new PropertyValue[1];
  properties[0] = new PropertyValue();
  properties[0].Name = "nodepath";
  properties[0].Value = path;
  Object configReadAccessObject = xConfigServiceFactory.createInstanceWithArguments(readConfAccess,
      properties);
  XNameAccess xConfigNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,
      configReadAccessObject);
  return xConfigNameAccess.getByName(key);
}
 
Example #2
Source File: TextRange.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns related page style of the text range.
 * 
 * @return page style of the text range
 * 
 * @throws TextException if the page style is not available
 * 
 * @author Andreas Bröker
 */
public IPageStyle getPageStyle() throws TextException {
  if(document == null || !(document instanceof ITextDocument))
  	throw new TextException("Text style not available");
	try {
    XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextRange);
    String pageStyleName = xPropertySet.getPropertyValue("PageStyleName").toString();
    XStyleFamiliesSupplier xStyleFamiliesSupplier = (XStyleFamiliesSupplier)UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, ((ITextDocument)document).getXTextDocument());
    XNameAccess xNameAccess = xStyleFamiliesSupplier.getStyleFamilies();
    Any any = (Any)xNameAccess.getByName("PageStyles");
    XNameContainer xNameContainer = (XNameContainer)any.getObject();
    any = (Any)xNameContainer.getByName(pageStyleName);
    XStyle style = (XStyle)any.getObject();
    return new PageStyle(style);
  }
  catch(Exception exception) {
    TextException textException = new TextException(exception.getMessage());
    textException.initCause(exception);
    throw textException;
  }
}
 
Example #3
Source File: TextTableService.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns all available text tables.
 * 
 * @return all available text tables
 * 
 * @author Andreas Bröker
 */
public ITextTable[] getTextTables() {
  XTextTablesSupplier xTextTablesSupplier = (XTextTablesSupplier)UnoRuntime.queryInterface(XTextTablesSupplier.class, textDocument.getXTextDocument());
  XNameAccess xNameAccess = xTextTablesSupplier.getTextTables();
  XIndexAccess xIndexAccess = (XIndexAccess)UnoRuntime.queryInterface(XIndexAccess.class, xNameAccess);
  ITextTable[] textTables = new ITextTable[xIndexAccess.getCount()];
  for(int i=0, n=xIndexAccess.getCount(); i<n; i++) {
    try {
      Any any = (Any)xIndexAccess.getByIndex(i);
      XTextTable textTable = (XTextTable)any.getObject();
      if(textTable.getColumns().getCount() <= ITextTable.MAX_COLUMNS_IN_TABLE) {
        textTables[i] = new TextTable(textDocument, textTable);
    	}
    }
    catch(Exception exception) {
      //do nothing
    }
  }
  return textTables;
}
 
Example #4
Source File: TextTableService.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns table with the submitted name.
 * 
 * @param name name of the table
 * 
 * @return table with the submitted name
 * 
 * @throws TextException if the table does not exist
 * 
 * @author Andreas Bröker
 */
public ITextTable getTextTable(String name) throws TextException {
  try {
    XTextTablesSupplier xTextTablesSupplier = (XTextTablesSupplier)UnoRuntime.queryInterface(XTextTablesSupplier.class, textDocument.getXTextDocument());
    XNameAccess xNameAccess = xTextTablesSupplier.getTextTables();
    Any any = (Any)xNameAccess.getByName(name);
    XTextTable textTable = (XTextTable)any.getObject();
    if(textTable.getColumns().getCount() <= ITextTable.MAX_COLUMNS_IN_TABLE) {
    	return new TextTable(textDocument, textTable);
    }
    else {
    	throw new TextException("The submitted table is not valid");
    }
  }
  catch(Exception exception) {
    TextException textException = new TextException(exception.getMessage());
    textException.initCause(exception);
    throw textException;
  }
}
 
Example #5
Source File: OpenOfficeWorker.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public static List<String> getFilterNames(XMultiComponentFactory xmulticomponentfactory) throws Exception {
    XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xmulticomponentfactory);
    Object oDefaultContext = xPropertySet.getPropertyValue("DefaultContext");
    XComponentContext xComponentContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, oDefaultContext);


    Object filterFactory = xmulticomponentfactory.createInstanceWithContext("com.sun.star.document.FilterFactory", xComponentContext);
    XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface(XNameAccess.class, filterFactory);
    String [] filterNames = xNameAccess.getElementNames();

    //String [] serviceNames = filterFactory.getAvailableServiceNames();
    for (int i=0; i < filterNames.length; i++) {
        String s = filterNames[i];
        Debug.logInfo(s, module);
        /*
        if (s.toLowerCase().indexOf("filter") >= 0) {
            Debug.logInfo("FILTER: " + s, module);
        }
        if (s.toLowerCase().indexOf("desktop") >= 0) {
            Debug.logInfo("DESKTOP: " + s, module);
        }
        */
    }

    List<String> filterNameList = UtilMisc.toListArray(filterNames);
    return filterNameList;
}
 
Example #6
Source File: ApplicationInfo.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method dumps info from the application described by the path.
 * 
 * @param path the path to be dumped, or null to dump from root
 * 
 * @throws Exception if dumping info fails
 * 
 * @author Markus Krüger
 * @date 18.11.2008
 */
public void dumpInfo(String path) throws Exception {
  if (path == null || path.length() == 0)
    path = NODE_ROOT;
  Object configProviderObject = serviceProvider.createService("com.sun.star.comp.configuration.ConfigurationProvider");
  XMultiServiceFactory xConfigServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class,
      configProviderObject);
  String readConfAccess = "com.sun.star.configuration.ConfigurationAccess";
  PropertyValue[] properties = new PropertyValue[1];
  properties[0] = new PropertyValue();
  properties[0].Name = "nodepath";
  properties[0].Value = path;
  Object configReadAccessObject = xConfigServiceFactory.createInstanceWithArguments(readConfAccess,
      properties);
  XNameAccess xConfigNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,
      configReadAccessObject);
  String[] names = xConfigNameAccess.getElementNames();
  System.out.println(path);
  System.out.println("=======================================");
  for (int i = 0; i < names.length; i++) {
    Object element = xConfigNameAccess.getByName(names[i]);
    if (element instanceof String || element instanceof Boolean
        || element instanceof Number
        || element instanceof Character
        || element instanceof CharSequence) {
      System.out.println(names[i] + ": "
          + element);
    }
    else if (element instanceof String[]) {
      System.out.println(names[i] + ": "
          + Arrays.asList((String[]) element).toString());
    }
    else if (!(element instanceof Any)) {
      dumpInfo(path + "/"
          + names[i]);
    }
  }
}
 
Example #7
Source File: TextFieldService.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns master of a user textfield with the submitted name. Returns null
 * if a user textfield with the submitted name is not available.
 * 
 * @param name
 *            name of the master of the user textfield
 * 
 * @return master of a user textfield with the submitted name or null if a
 *         user textfield with the submitted name is not available
 * 
 * @throws TextException
 *             if the user text field can not be provided
 * 
 * @author Andreas Bröker
 */
public ITextFieldMaster getUserTextFieldMaster(String name)
		throws TextException {
	try {
		XTextFieldsSupplier xTextFieldsSupplier = (XTextFieldsSupplier) UnoRuntime
				.queryInterface(XTextFieldsSupplier.class,
						textDocument.getXTextDocument());
		XNameAccess xNameAccess = xTextFieldsSupplier.getTextFieldMasters();
		Any any = null;

		try {
			any = (Any) xNameAccess.getByName(USER_TEXTFIELD_MASTER_PREFIX
					+ name);
		} catch (NoSuchElementException noSuchElementException) {
			return null;
		}

		XPropertySet xPropertySet = (XPropertySet) UnoRuntime
				.queryInterface(XPropertySet.class, any);
		if (xPropertySet != null) {
			return new TextFieldMaster(textDocument, xPropertySet);
		} else {
			return null;
		}
	} catch (Exception exception) {
		throw new TextException(exception);
	}
}
 
Example #8
Source File: TextFieldService.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns master of the variables text fields with the submitted name, or
 * null if not availbale.
 * 
 * @param masterName
 *            name of the master to return
 * 
 * @return master of the variables text fields with the submitted name, or
 *         null
 * 
 * @throws TextException
 *             if the master can not be returned
 * 
 * @author Markus Krüger
 * @date 30.05.2007
 */
public IVariableTextFieldMaster getVariableTextFieldMaster(String masterName)
		throws TextException {
	try {
		XTextFieldsSupplier xTextFieldsSupplier = (XTextFieldsSupplier) UnoRuntime
				.queryInterface(XTextFieldsSupplier.class,
						textDocument.getXTextDocument());
		XNameAccess xNameAccess = xTextFieldsSupplier.getTextFieldMasters();
		Any any = null;

		try {
			String name = masterName;
			if (!name.toLowerCase().startsWith(
					VARIABLES_TEXTFIELD_MASTER_PREFIX.toLowerCase())) {
				name = VARIABLES_TEXTFIELD_MASTER_PREFIX + name;
			}
			any = (Any) xNameAccess.getByName(name);
		} catch (NoSuchElementException noSuchElementException) {
			return null;
		}

		XPropertySet xPropertySet = (XPropertySet) UnoRuntime
				.queryInterface(XPropertySet.class, any);
		if (xPropertySet != null) {
			return new VariableTextFieldMaster(textDocument, xPropertySet);
		}
		return null;
	} catch (Exception exception) {
		throw new TextException(exception);
	}
}
 
Example #9
Source File: TextFieldService.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns all masters of the variables text fields with the submitted name
 * prefix.
 * 
 * @param prefix
 *            name prefix to be used
 * 
 * @return all masters of the variables text fields
 * 
 * @throws TextException
 *             if the masters can not be returned
 * 
 * @author Markus Krüger
 * @date 30.05.2007
 */
public IVariableTextFieldMaster[] getVariableTextFieldMasters(String prefix)
		throws TextException {
	try {
		XTextFieldsSupplier xTextFieldsSupplier = (XTextFieldsSupplier) UnoRuntime
				.queryInterface(XTextFieldsSupplier.class,
						textDocument.getXTextDocument());
		XNameAccess xNameAccess = xTextFieldsSupplier.getTextFieldMasters();
		String[] names = xNameAccess.getElementNames();
		List masters = new ArrayList();
		for (int i = 0; i < names.length; i++) {
			if (names[i].toLowerCase().startsWith(
					(VARIABLES_TEXTFIELD_MASTER_PREFIX + prefix)
							.toLowerCase())) {
				Any any = null;
				try {
					any = (Any) xNameAccess.getByName(names[i]);
				} catch (NoSuchElementException noSuchElementException) {
					continue;
				}
				XPropertySet xPropertySet = (XPropertySet) UnoRuntime
						.queryInterface(XPropertySet.class, any);
				if (xPropertySet != null) {
					masters.add(new VariableTextFieldMaster(textDocument,
							xPropertySet));
				}
			}
		}
		return (IVariableTextFieldMaster[]) masters
				.toArray(new IVariableTextFieldMaster[masters.size()]);
	} catch (Exception exception) {
		throw new TextException(exception);
	}
}
 
Example #10
Source File: TextContentService.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Convert linked text images to embedded images.
 * 
 * @throws TextException if conversion fails
 * 
 * @author Markus Krüger
 * @date 07.09.2009
 */
public void convertLinkedImagesToEmbeded() throws TextException {
  try {
    XTextGraphicObjectsSupplier graphicObjSupplier = (XTextGraphicObjectsSupplier) UnoRuntime.queryInterface(XTextGraphicObjectsSupplier.class,
        textDocument.getXTextDocument());
    XNameAccess nameAccess = graphicObjSupplier.getGraphicObjects();
    String[] names = nameAccess.getElementNames();
    for (int i = 0; i < names.length; i++) {
      Any xImageAny = (Any) nameAccess.getByName(names[i]);
      Object xImageObject = xImageAny.getObject();
      XTextContent xImage = (XTextContent) xImageObject;
      XServiceInfo xInfo = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, xImage);
      if (xInfo.supportsService("com.sun.star.text.TextGraphicObject")) {
        XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
            xImage);
        String name = xPropSet.getPropertyValue("LinkDisplayName").toString();
        String graphicURL = xPropSet.getPropertyValue("GraphicURL").toString();
        //only ones that are not embedded
        if (graphicURL.indexOf("vnd.sun.") == -1) {
          XMultiServiceFactory multiServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class,
              textDocument.getXTextDocument());
          XNameContainer xBitmapContainer = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class,
              multiServiceFactory.createInstance("com.sun.star.drawing.BitmapTable"));
          if (!xBitmapContainer.hasByName(name)) {
            xBitmapContainer.insertByName(name, graphicURL);
            String newGraphicURL = xBitmapContainer.getByName(name).toString();
            xPropSet.setPropertyValue("GraphicURL", newGraphicURL);
          }
        }
      }
    }
  }
  catch (Exception exception) {
    TextException textException = new TextException(exception.getMessage());
    textException.initCause(exception);
    throw textException;
  }
}
 
Example #11
Source File: BookmarkService.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns all bookmarks.
 * 
 * @return all bookmarks
 * 
 * @author Markus Krüger
 */
public IBookmark[] getBookmarks() {
  try {
    XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier) UnoRuntime.queryInterface(XBookmarksSupplier.class,
        textDocument.getXTextDocument());
    if (xBookmarksSupplier == null)
      return new IBookmark[0];
    XNameAccess nameAccess = xBookmarksSupplier.getBookmarks();
    String[] names = nameAccess.getElementNames();
    if (names.length < 1)
      return new IBookmark[0];
    List bookmarks = new ArrayList();
    for (int i = 0; i < names.length; i++) {
      Object bookmark = nameAccess.getByName(names[i]);
      XTextContent xBookmarkContent = (XTextContent) UnoRuntime.queryInterface(XTextContent.class,
          bookmark);
      XNamed xNamed = (XNamed) UnoRuntime.queryInterface(XNamed.class, bookmark);
      if (xBookmarkContent == null)
        continue;
      XTextRange xBookmarkRange = xBookmarkContent.getAnchor();
      if (xBookmarkRange == null)
        continue;
      bookmarks.add(new Bookmark(textDocument, xBookmarkRange, xNamed));
    }
    return (IBookmark[]) bookmarks.toArray(new IBookmark[bookmarks.size()]);
  }
  catch (Exception exception) {
    return new IBookmark[0];
  }
}
 
Example #12
Source File: TableManager.java    From yarg with Apache License 2.0 4 votes vote down vote up
public static List<String> getTablesNames(XComponent xComponent) {
    XNameAccess tables = as(XTextTablesSupplier.class, xComponent).getTextTables();
    return new ArrayList<String>(Arrays.asList(tables.getElementNames()));
}
 
Example #13
Source File: TableManager.java    From yarg with Apache License 2.0 4 votes vote down vote up
public static XTextTable getTableByName(XComponent xComponent, String tableName) throws NoSuchElementException, WrappedTargetException {
    XNameAccess tables = as(XTextTablesSupplier.class, xComponent).getTextTables();
    return (XTextTable) ((Any) tables.getByName(tableName)).getObject();
}