com.sun.star.lang.XServiceInfo Java Examples

The following examples show how to use com.sun.star.lang.XServiceInfo. 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: OfficeDocumentUtils.java    From kkFileViewOfficeEdit with Apache License 2.0 6 votes vote down vote up
public static DocumentFamily getDocumentFamily(XComponent document) throws OfficeException {
    XServiceInfo serviceInfo = cast(XServiceInfo.class, document);
    if (serviceInfo.supportsService("com.sun.star.text.GenericTextDocument")) {
        // NOTE: a GenericTextDocument is either a TextDocument, a WebDocument, or a GlobalDocument
        // but this further distinction doesn't seem to matter for conversions
        return DocumentFamily.TEXT;
    } else if (serviceInfo.supportsService("com.sun.star.sheet.SpreadsheetDocument")) {
        return DocumentFamily.SPREADSHEET;
    } else if (serviceInfo.supportsService("com.sun.star.presentation.PresentationDocument")) {
        return DocumentFamily.PRESENTATION;
    } else if (serviceInfo.supportsService("com.sun.star.drawing.DrawingDocument")) {
        return DocumentFamily.DRAWING;
    } else {
        throw new OfficeException("document of unknown family: " + serviceInfo.getImplementationName());
    }
}
 
Example #2
Source File: OfficeDocumentUtils.java    From kkFileView with Apache License 2.0 6 votes vote down vote up
public static DocumentFamily getDocumentFamily(XComponent document) throws OfficeException {
    XServiceInfo serviceInfo = cast(XServiceInfo.class, document);
    if (serviceInfo.supportsService("com.sun.star.text.GenericTextDocument")) {
        // NOTE: a GenericTextDocument is either a TextDocument, a WebDocument, or a GlobalDocument
        // but this further distinction doesn't seem to matter for conversions
        return DocumentFamily.TEXT;
    } else if (serviceInfo.supportsService("com.sun.star.sheet.SpreadsheetDocument")) {
        return DocumentFamily.SPREADSHEET;
    } else if (serviceInfo.supportsService("com.sun.star.presentation.PresentationDocument")) {
        return DocumentFamily.PRESENTATION;
    } else if (serviceInfo.supportsService("com.sun.star.drawing.DrawingDocument")) {
        return DocumentFamily.DRAWING;
    } else {
        throw new OfficeException("document of unknown family: " + serviceInfo.getImplementationName());
    }
}
 
Example #3
Source File: OfficeDocumentUtils.java    From wenku with MIT License 6 votes vote down vote up
public static DocumentFamily getDocumentFamily(XComponent document) throws OfficeException {
    XServiceInfo serviceInfo = cast(XServiceInfo.class, document);
    if (serviceInfo.supportsService("com.sun.star.text.GenericTextDocument")) {
        // NOTE: a GenericTextDocument is either a TextDocument, a WebDocument, or a GlobalDocument
        // but this further distinction doesn't seem to matter for conversions
        return DocumentFamily.TEXT;
    } else if (serviceInfo.supportsService("com.sun.star.sheet.SpreadsheetDocument")) {
        return DocumentFamily.SPREADSHEET;
    } else if (serviceInfo.supportsService("com.sun.star.presentation.PresentationDocument")) {
        return DocumentFamily.PRESENTATION;
    } else if (serviceInfo.supportsService("com.sun.star.drawing.DrawingDocument")) {
        return DocumentFamily.DRAWING;
    } else {
        throw new OfficeException("document of unknown family: " + serviceInfo.getImplementationName());
    }
}
 
Example #4
Source File: Annotation.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns the text content of the annotation, or null if text content is not available.
 * 
 * @return the text content of the annotation, or null
 * 
 * @author Markus Krüger
 * @date 13.07.2006
 */
public String getText() {
  XServiceInfo info = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, getXTextContent());
  if(info.supportsService(ITextFieldService.ANNOTATION_TEXTFIELD_ID)) {
    XPropertySet properties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, getXTextContent());
    try {
      return (String) properties.getPropertyValue("Content");
    }
    catch(UnknownPropertyException unknownPropertyException) {
      //TODO exception handling if needed, do nothing for now
    }
    catch(WrappedTargetException wrappedTargetException) {
      //TODO exception handling if needed, do nothing for now
    }
  }
  return null;
}
 
Example #5
Source File: AnnotationService.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns all annotations.
 * 
 * @return all annotations
 * 
 * @author Markus Krüger
 * @date 13.07.2006
 */
public IAnnotation[] getAnnotations() {
  try {
    ITextField[] fields = textDocument.getTextFieldService().getUserTextFields();
    List annotations = new ArrayList();
    for(int i = 0; i < fields.length; i++) {
      XServiceInfo info = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, fields[i].getXTextContent());
      if(info.supportsService(ITextFieldService.ANNOTATION_TEXTFIELD_ID)) {
        annotations.add(new Annotation(textDocument,fields[i]));
      }
    } 
    return (IAnnotation[]) annotations.toArray(new IAnnotation[annotations.size()]);
  }
  catch (Throwable throwable) {
    return new IAnnotation[0];
  }
}
 
Example #6
Source File: Annotation.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns the text content of the annotation, or null if text content is not available.
 * 
 * @return the text content of the annotation, or null
 * 
 * @author Markus Krüger
 * @date 13.07.2006
 */
public String getText() {
  XServiceInfo info = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, getXTextContent());
  if(info.supportsService(ITextFieldService.ANNOTATION_TEXTFIELD_ID)) {
    XPropertySet properties = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, getXTextContent());
    try {
      return (String) properties.getPropertyValue("Content");
    }
    catch(UnknownPropertyException unknownPropertyException) {
      //TODO exception handling if needed, do nothing for now
    }
    catch(WrappedTargetException wrappedTargetException) {
      //TODO exception handling if needed, do nothing for now
    }
  }
  return null;
}
 
Example #7
Source File: AnnotationService.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns all annotations.
 * 
 * @return all annotations
 * 
 * @author Markus Krüger
 * @date 13.07.2006
 */
public IAnnotation[] getAnnotations() {
  try {
    ITextField[] fields = textDocument.getTextFieldService().getUserTextFields();
    List annotations = new ArrayList();
    for(int i = 0; i < fields.length; i++) {
      XServiceInfo info = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, fields[i].getXTextContent());
      if(info.supportsService(ITextFieldService.ANNOTATION_TEXTFIELD_ID)) {
        annotations.add(new Annotation(textDocument,fields[i]));
      }
    } 
    return (IAnnotation[]) annotations.toArray(new IAnnotation[annotations.size()]);
  }
  catch (Exception exception) {
    return new IAnnotation[0];
  }
}
 
Example #8
Source File: TextContentService.java    From noa-libre with GNU Lesser General Public License v2.1 6 votes vote down vote up
private IParagraph[] getRealParagraphs() throws Exception {
  XEnumerationAccess xEnumerationAccess = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class,
      textDocument.getTextService().getText().getXText());
  XEnumeration xParagraphEnumeration = xEnumerationAccess.createEnumeration();
  List<IParagraph> realParagraphs = new ArrayList<IParagraph>();
  while (xParagraphEnumeration.hasMoreElements()) {
    XTextContent xTextContent = (XTextContent) UnoRuntime.queryInterface(XTextContent.class,
        xParagraphEnumeration.nextElement());
    XServiceInfo xServiceInfo = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class,
        xTextContent);
    if (xServiceInfo.supportsService("com.sun.star.text.Paragraph")) {
      realParagraphs.add(new Paragraph(textDocument, xTextContent));
    }
  }
  return realParagraphs.toArray(new IParagraph[realParagraphs.size()]);
}
 
Example #9
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;
  }
}