コード例 #1
0
  private BungeniMessage validateAction_TextSelectedInsertAction() {
    BungeniMessage validMessage = new BungeniMessage();
    // check if text was selected
    if ((ooDocument.isTextSelected() == false)
        || (ooDocument.isTextGraphicObjectSelected() == false)) {
      // fail if no text was selected
      return new BungeniMessage(
          BungeniError.TEXT_SELECTED_INSERT_ACTION_FAIL, BungeniError.NO_TEXT_SELECTED);
    }

    if (m_subAction.sub_action_name().equals("section_creation")) {
      validMessage = validateAction_TextSelectedInsertAction_CreateSection();
      return validMessage;
    } else if (m_subAction.sub_action_name().equals("debatedate_entry")) {
      validMessage = validateAction_TextSelectedInsertAction_DebateDateEntry();
      return validMessage;
    } else if (m_subAction.sub_action_name().equals("debatetime_entry")) {
      validMessage = validateAction_TextSelectedInsertAction_DebateTimeEntry();
      return validMessage;
    } else if (m_subAction.sub_action_name().equals("markup_logo")) {
      validMessage = validateAction_TextSelectedInsertAction_MarkupLogo();
      return validMessage;
    } else {
      log.debug("validateAction_DocumentLevelAction() : method not implemented");
      return new BungeniMessage(
          BungeniError.TEXT_SELECTED_INSERT_ACTION_FAIL, BungeniError.METHOD_NOT_IMPLEMENTED);
    }
  }
コード例 #2
0
 private boolean action_addSectionIntoSectionwithStyling(
     OOComponentHelper ooDoc,
     String parentSection,
     String newSectionName,
     long sectionBackColor,
     float sectionLeftMargin) {
   boolean bState = false;
   try {
     ExternalMacro AddSectionInsideSection =
         ExternalMacroFactory.getMacroDefinition("AddSectionInsideSectionWithStyle");
     AddSectionInsideSection.addParameter(ooDoc.getComponent());
     AddSectionInsideSection.addParameter(parentSection);
     AddSectionInsideSection.addParameter(newSectionName);
     AddSectionInsideSection.addParameter(sectionBackColor);
     AddSectionInsideSection.addParameter(sectionLeftMargin);
     ooDoc.executeMacro(AddSectionInsideSection.toString(), AddSectionInsideSection.getParams());
     bState = true;
   } catch (Exception ex) {
     log.error("action_addSectionIntoSectionwithStyling: error : " + ex.getMessage());
     // checkFieldsMessages.add(ex.getLocalizedMessage());
     bState = false;
   } finally {
     return bState;
   }
 }
コード例 #3
0
 private int check_systemContainerPositionCheck() {
   String systemContainer = m_subAction.system_container();
   if (ooDocument.hasSection(systemContainer)) {
     String currentSection = ooDocument.currentSectionName();
     if (currentSection.equals(systemContainer)) {
       return BungeniError.SYSTEM_CONTAINER_ALREADY_EXISTS;
     } else {
       return BungeniError.SYSTEM_CONTAINER_WRONG_POSITION;
     }
   } else {
     return BungeniError.SYSTEM_CONTAINER_CHECK_OK;
   }
 }
コード例 #4
0
  @Override
  public boolean validateSelectedInsert() {
    OOComponentHelper ooDoc = getContainerPanel().getOoDocument();
    XNameAccess refs = ooDoc.getReferenceMarks();
    if (refs.hasByName(_debatetimeRefName_)) {
      this.addErrorMessage(
          null,
          "This item has already been marked up. Please use the 'Edit Metadata' option to modify it");
      return false;
    }

    return true;
  }
コード例 #5
0
 private boolean action_removeSectionWithoutContents(OOComponentHelper ooDoc, String sectionName) {
   boolean bResult = false;
   try {
     XTextSection theSection = ooDocument.getSection(sectionName);
     XText docText = ooDocument.getTextDocument().getText();
     docText.removeTextContent(theSection);
     bResult = true;
   } catch (NoSuchElementException ex) {
     log.error("in removeSectionWIthoutContents : " + ex.getLocalizedMessage(), ex);
     bResult = false;
   } finally {
     return bResult;
   }
 }
コード例 #6
0
  /*
   *
   *This is a generic check, because a system action is always a generic action with generic validation
   *
   *
   */
  private BungeniMessage validateAction_TextSelectedSystemAction() {
    int nRetValue = -1;
    BungeniMessage theMessage = new BungeniMessage();
    // 1st check ... look for root
    nRetValue = check_rootContainerExists();
    if (nRetValue == BungeniError.DOCUMENT_ROOT_DOES_NOT_EXIST) {
      return new BungeniMessage(
          BungeniError.TEXT_SELECTED_SYSTEM_ACTION_FAIL, BungeniError.DOCUMENT_ROOT_DOES_NOT_EXIST);
    }
    // 2nd check ... if text was selected
    if (ooDocument.isTextSelected() == false) {
      // fail if no text was selected
      return new BungeniMessage(
          BungeniError.TEXT_SELECTED_INSERT_ACTION_FAIL, BungeniError.NO_TEXT_SELECTED);
    }
    // 3rd check ... if system container can be created here
    if (m_subAction.sub_action_name().equals("debatedate_entry")) {
      theMessage = validateAction_TextSelectedSystemAction_DebateDateEntry();
      return theMessage;
    } else if (m_subAction.sub_action_name().equals("debatetime_entry")) {
      theMessage = validateAction_TextSelectedSystemAction_DebateTimeEntry();
      return theMessage;
    }
    /*
    nRetValue = check_canSystemContainerBeCreated();
    if (nRetValue == BungeniError.INVALID_CONTAINER_FOR_SYSTEM_ACTION) {
        return new BungeniMessage(BungeniError.TEXT_SELECTED_SYSTEM_ACTION_FAIL, BungeniError.INVALID_CONTAINER_FOR_SYSTEM_ACTION);
    }
    */

    return new BungeniMessage(BungeniError.TEXT_SELECTED_SYSTEM_ACTION_PROCEED, nRetValue);
  }
コード例 #7
0
 private boolean action_createSystemContainerFromSelection(
     OOComponentHelper ooDoc, String systemContainerName) {
   boolean bResult = false;
   try {
     XTextViewCursor xCursor = ooDocument.getViewCursor();
     XText xText = xCursor.getText();
     XTextContent xSectionContent = ooDocument.createTextSection(systemContainerName, (short) 1);
     xText.insertTextContent(xCursor, xSectionContent, true);
     bResult = true;
   } catch (com.sun.star.lang.IllegalArgumentException ex) {
     bResult = false;
     log.error("in addTextSection : " + ex.getLocalizedMessage(), ex);
   } finally {
     return bResult;
   }
 }
コード例 #8
0
  private BungeniMessage validateAction_TextSelectedInsertAction_CreateSection() {
    int nRetValue = -1;

    // 1st tier, root container check
    nRetValue = check_rootContainerExists();
    if (nRetValue == BungeniError.DOCUMENT_ROOT_DOES_NOT_EXIST) {
      return new BungeniMessage(
          BungeniError.TEXT_SELECTED_INSERT_ACTION_FAIL, BungeniError.DOCUMENT_ROOT_DOES_NOT_EXIST);
    }
    // 2nd tier validation ...check up the hierarchy
    // check if there is a current section, and if the section can be created in the current section
    String currentSectionname = ooDocument.currentSectionName();
    nRetValue = check_containment(currentSectionname);
    if (nRetValue == BungeniError.INVALID_SECTION_CONTAINER) {
      return new BungeniMessage(
          BungeniError.TEXT_SELECTED_INSERT_ACTION_FAIL, BungeniError.INVALID_SECTION_CONTAINER);
    }

    // 3rd tier validation
    // check if section already exists (only for single type section)
    nRetValue = check_actionSectionExists();
    if (nRetValue == BungeniError.SECTION_EXISTS) {
      return new BungeniMessage(
          BungeniError.TEXT_SELECTED_INSERT_ACTION_FAIL, BungeniError.SECTION_EXISTS);
    }

    return new BungeniMessage(BungeniError.TEXT_SELECTED_INSERT_ACTION_PROCEED, nRetValue);
  }
コード例 #9
0
 private int check_canSystemContainerBeCreated() {
   // this is the actual container section type
   String containerSectionType = m_parentAction.action_section_type();
   // this is the current section where the cursor is, we want to compare actual container
   // section type with required.
   String currentSection = ooDocument.currentSectionName();
   HashMap<String, String> metaMap = ooDocument.getSectionMetadataAttributes(currentSection);
   if (metaMap.containsKey("BungeniSectionType")) {
     String currentSectionType = metaMap.get("BungeniSectionType");
     if (currentSectionType.equals(containerSectionType)) {
       return BungeniError.VALID_CONTAINER_FOR_SYSTEM_ACTION;
     } else {
       return BungeniError.INVALID_CONTAINER_FOR_SYSTEM_ACTION;
     }
   } else return BungeniError.INVALID_CONTAINER_FOR_SYSTEM_ACTION;
 }
コード例 #10
0
 private BungeniMessage validateAction_TextSelectedInsertAction_DebateDateEntry() {
   int nRetValue = -1;
   /*
   if (m_subAction.system_container().length() > 0 ) {
       nRetValue = check_systemContainerExists();
       if (nRetValue == BungeniError.SYSTEM_CONTAINER_NOT_PRESENT){
           return new BungeniMessage(BungeniError.TEXT_SELECTED_INSERT_ACTION_FAIL, nRetValue);
       }
       nRetValue = this.check_generic_systemContainerCheck();
           switch (nRetValue) {
               case BungeniError.SYSTEM_CONTAINER_ALREADY_EXISTS:
               case BungeniError.SYSTEM_CONTAINER_WRONG_POSITION:
               case BungeniError.INVALID_CONTAINER_FOR_SYSTEM_ACTION:
                   return new BungeniMessage(BungeniError.TEXT_SELECTED_INSERT_ACTION_FAIL, nRetValue);
               default:
                   return new BungeniMessage(BungeniError.TEXT_SELECTED_INSERT_ACTION_PROCEED, nRetValue);
            }
   } else { */
   String currentSection = ooDocument.currentSectionName();
   nRetValue = this.check_containment(currentSection);
   if (nRetValue == BungeniError.VALID_SECTION_CONTAINER)
     return new BungeniMessage(
         BungeniError.TEXT_SELECTED_INSERT_ACTION_PROCEED, BungeniError.VALID_SECTION_CONTAINER);
   else
     return new BungeniMessage(
         BungeniError.TEXT_SELECTED_INSERT_ACTION_FAIL, BungeniError.INVALID_SECTION_CONTAINER);
   /* } */
 }
コード例 #11
0
 private boolean action_createRootSection(OOComponentHelper ooDoc, String sectionName) {
   boolean bResult = false;
   try {
     XText docText = ooDocument.getTextDocument().getText();
     XTextCursor docCursor = docText.createTextCursor();
     docCursor.gotoStart(false);
     docCursor.gotoEnd(true);
     XTextContent theContent = ooDocument.createTextSection(sectionName, (short) 1);
     docText.insertTextContent(docCursor, theContent, true);
     bResult = true;
   } catch (IllegalArgumentException ex) {
     log.error("in action_createRootSection :" + ex.getMessage());
     log.error("in action_createRootSection :" + CommonExceptionUtils.getStackTrace(ex));
   } finally {
     return bResult;
   }
 }
コード例 #12
0
 private int check_systemContainerExists() {
   String systemContainer = m_subAction.system_container();
   if (ooDocument.hasSection(systemContainer)) {
     return BungeniError.SYSTEM_CONTAINER_ALREADY_EXISTS;
   } else {
     return BungeniError.SYSTEM_CONTAINER_NOT_PRESENT;
   }
 }
コード例 #13
0
 private int check_rootContainerExists() {
   String rootSectionname = CommonPropertyFunctions.getDocumentRootSection();
   if (ooDocument.hasSection(rootSectionname)) {
     return BungeniError.DOCUMENT_ROOT_EXISTS;
   } else {
     return BungeniError.DOCUMENT_ROOT_DOES_NOT_EXIST;
   }
 }
コード例 #14
0
 private boolean action_replaceTextWithField(
     OOComponentHelper ooDoc, String hintName, String hintPlaceholderValue) {
   boolean bState = false;
   try {
     ExternalMacro ReplaceTextWithField =
         ExternalMacroFactory.getMacroDefinition("ReplaceTextWithField");
     ReplaceTextWithField.addParameter(ooDoc.getComponent());
     ReplaceTextWithField.addParameter(hintName);
     ReplaceTextWithField.addParameter(hintPlaceholderValue);
     ooDoc.executeMacro(ReplaceTextWithField.toString(), ReplaceTextWithField.getParams());
     bState = true;
   } catch (Exception ex) {
     log.error("action_replaceTextWithField: error : " + ex.getMessage());
     // checkFieldsMessages.add(ex.getLocalizedMessage());
     bState = false;
   } finally {
     return bState;
   }
 }
コード例 #15
0
 private boolean action_addDocIntoSection(
     OOComponentHelper ooDoc, String intoSection, String fragmentName) {
   boolean bState = false;
   try {
     ExternalMacro insertDocIntoSection =
         ExternalMacroFactory.getMacroDefinition("InsertDocumentIntoSection");
     insertDocIntoSection.addParameter(ooDoc.getComponent());
     insertDocIntoSection.addParameter(intoSection);
     insertDocIntoSection.addParameter(fragmentName);
     ooDoc.executeMacro(insertDocIntoSection.toString(), insertDocIntoSection.getParams());
     bState = true;
   } catch (Exception ex) {
     log.error("action_addImageIntoSection: error : " + ex.getMessage());
     // checkFieldsMessages.add(ex.getLocalizedMessage());
     bState = false;
   } finally {
     return bState;
   }
 }
コード例 #16
0
 private boolean action_setInputFieldValue(
     OOComponentHelper ooDoc, String hintName, String strDebateDate, String unprotectSection) {
   boolean bState = false;
   try {
     ExternalMacro setFieldValue =
         ExternalMacroFactory.getMacroDefinition("SetReferenceInputFieldValue");
     setFieldValue.addParameter(ooDoc.getComponent());
     setFieldValue.addParameter(hintName);
     setFieldValue.addParameter(strDebateDate);
     setFieldValue.addParameter(unprotectSection);
     ooDoc.executeMacro(setFieldValue.toString(), setFieldValue.getParams());
     bState = true;
   } catch (Exception ex) {
     log.error("action_addImageIntoSection: error : " + ex.getMessage());
     // checkFieldsMessages.add(ex.getLocalizedMessage());
     bState = false;
   } finally {
     return bState;
   }
 }
コード例 #17
0
 private int check_actionSectionExists() {
   if (m_parentAction.action_numbering_convention().equals("single")) {
     if (ooDocument.hasSection(m_parentAction.action_naming_convention())) {
       return BungeniError.SECTION_EXISTS;
     } else {
       return BungeniError.SECTION_DOES_NOT_EXIST;
     }
   } else { // if section style is not single then multiple instances of the section can be
            // created.
     return BungeniError.SECTION_DOES_NOT_EXIST;
   }
 }
コード例 #18
0
 private void insertRefMark(
     OOComponentHelper ooHandle, XTextCursor thisCursor, String referenceName) {
   Object referenceMark = ooHandle.createInstance("com.sun.star.text.ReferenceMark");
   XNamed xRefMark = ooQueryInterface.XNamed(referenceMark);
   xRefMark.setName(referenceName);
   XTextContent xContent = ooQueryInterface.XTextContent(xRefMark);
   try {
     thisCursor.getText().insertTextContent(thisCursor, xContent, true);
   } catch (Exception ex) {
     log.error("insertReferenceMark :" + ex.getMessage());
   }
 }
コード例 #19
0
 private boolean action_addImageIntoSection(
     OOComponentHelper ooDoc, String intoSection, String logoPath) {
   boolean bState = false;
   try {
     log.debug(
         "executing addImageIntoSection : intoSection = "
             + intoSection
             + " , logoPath = "
             + logoPath);
     ExternalMacro addImageIntoSection =
         ExternalMacroFactory.getMacroDefinition("AddImageIntoSection");
     addImageIntoSection.addParameter(ooDoc.getComponent());
     addImageIntoSection.addParameter(intoSection);
     addImageIntoSection.addParameter(logoPath);
     ooDoc.executeMacro(addImageIntoSection.toString(), addImageIntoSection.getParams());
     bState = true;
   } catch (Exception ex) {
     log.error("action_addImageIntoSection: error : " + ex.getMessage());
     // checkFieldsMessages.add(ex.getLocalizedMessage());
     bState = false;
   } finally {
     return bState;
   }
 }
コード例 #20
0
 @Override
 public boolean processSelectInsert() {
   // 1 check if reference exists .. if yes then fail...
   // if no markhighlighted text with named reference
   // also store selected date to metadata
   // 1 - add reference mark
   OOComponentHelper ooDoc = getContainerPanel().getOoDocument();
   insertRefMark(ooDoc, ooDoc.getViewCursor(), this._debatetimeRefName_);
   // 2 - add metadata
   SimpleDateFormat formatter =
       new SimpleDateFormat(BungeniEditorProperties.getEditorProperty("metadataTimeFormat"));
   Object timeValue = this.dt_initdebate_timeofhansard.getValue();
   Date hansardTime = (Date) timeValue;
   final String strTimeOfHansard = formatter.format(hansardTime);
   com.sun.star.text.XTextSection currentSection = ooDoc.currentSection();
   HashMap<String, String> sectionMeta =
       new HashMap<String, String>() {
         {
           put(_debatetimeRefName_, strTimeOfHansard);
         }
       };
   ooDoc.setSectionMetadataAttributes(currentSection, sectionMeta);
   return true;
 }
コード例 #21
0
  private int routeAction_TextSelectedInsertAction_CreateSection(BungeniMessage lastMessage) {
    String newSectionName = "";
    newSectionName = get_newSectionNameForAction(m_parentAction);
    if (newSectionName.length() == 0) {

    } else {
      boolean bAction = action_createSystemContainerFromSelection(ooDocument, newSectionName);
      if (bAction) {
        // set section type metadata
        ooDocument.setSectionMetadataAttributes(
            newSectionName, get_newSectionMetadata(m_parentAction));
      } else {
        log.error(
            "routeAction_TextSelectedInsertAction_CreateSection: error while creating section ");
      }
    }
    return 0;
  }
コード例 #22
0
  private int check_containment_Section(String currentContainerSection) {

    int error = BungeniError.GENERAL_ERROR;
    try {
      // get valid parent actions
      String strActionName = m_parentAction.action_name();
      dbSettings.Connect();
      String fetchParentQuery = SettingsQueryFactory.Q_FETCH_PARENT_ACTIONS(strActionName);
      log.debug("checkContainmentSection = " + fetchParentQuery);
      QueryResults qr = dbSettings.QueryResults(fetchParentQuery);
      dbSettings.EndConnect();
      String[] actionSectionTypes = qr.getSingleColumnResult("ACTION_SECTION_TYPE");
      // there can be multiple parents... so we iterate through the array if one of them is a valid
      // parent

      HashMap<String, String> sectionMetadata =
          ooDocument.getSectionMetadataAttributes(currentContainerSection);
      // if (sectionMetadata.get)
      String strDocSectionType = "";
      if (sectionMetadata.containsKey("BungeniSectionType")) {
        strDocSectionType = sectionMetadata.get("BungeniSectionType").trim();
        // check the doc section type against the array of valid action section types
        for (String sectionType : actionSectionTypes) {
          if (strDocSectionType.equals(sectionType.trim())) {
            error = BungeniError.VALID_SECTION_CONTAINER;
            break;
          } else {
            error = BungeniError.INVALID_SECTION_CONTAINER;
          }
        }
      } else {
        error = BungeniError.INVALID_SECTION_CONTAINER;
      }
    } catch (Exception ex) {
      log.error("check_containmentSection : " + ex.getMessage());
      log.error("check_containmentSection : " + CommonExceptionUtils.getStackTrace(ex));
    } finally {
      return error;
    }
  }
コード例 #23
0
  private String get_newSectionNameForAction(toolbarAction pAction) {
    String newSectionName = "";
    if (pAction.action_numbering_convention().equals("single")) {
      newSectionName = pAction.action_naming_convention();
    } else if (pAction.action_numbering_convention().equals("serial")) {
      String sectionPrefix = pAction.action_naming_convention();
      for (int i = 1; ; i++) {
        if (ooDocument.hasSection(sectionPrefix + i)) {
          continue;
        } else {
          newSectionName = sectionPrefix + i;
          break;
        }
      }

    } else {
      log.error(
          "get_newSectionNameForAction: invalid action naming convention: "
              + m_parentAction.action_naming_convention());
    }
    return newSectionName;
  }