Ejemplo n.º 1
0
  /**
   * Write the instance of IndexOfModelMappings back to the corresponding file (Used for
   * persistence)
   */
  public static synchronized void writeIndexBackToFile() {
    // Write file from the Vector
    File outFile = new File(Model3dIndex.getIndexPath() + "modelIndex.xml");
    try {
      outFile
          .createNewFile(); // will create it if it does not exist, otherwise will return false (we
                            // don't care)
      FileWriter tmpoutWriter = new FileWriter(outFile);
      WstxOutputFactory fout = new WstxOutputFactory();
      fout.configureForXmlConformance();
      SMOutputDocument doc = null;
      SMOutputElement outputRootEl = null;
      SMOutputElement outputRootEl2 = null;

      // output
      XMLStreamWriter2 sw = (XMLStreamWriter2) fout.createXMLStreamWriter(tmpoutWriter);
      doc = SMOutputFactory.createOutputDocument(sw, "1.0", "UTF-8", true);
      doc.setIndentation("\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t", 2, 1);
      outputRootEl = doc.addElement(Model3dIndex.getRootIndexTag());

      for (int i = 0; i < Model3dIndex.getListofAllMetaEntries().size(); i++) {
        outputRootEl2 = outputRootEl.addElement(Model3dIndex.getMetaEntryTag());
        Model3dIndex.getListofAllMetaEntries().elementAt(i).createInfoInDocument(outputRootEl2);
      }

      doc.closeRoot();
      tmpoutWriter.close();
    } catch (Exception e) {
      return;
    }
  }
Ejemplo n.º 2
0
 /**
  * Creates a new instance of Index Of Model Mappings read from the corresponding file (Used for
  * persistence)
  */
 public static void parseIndexFromFile() {
   // Read file and create the Index
   // check if file exists. If it exists open it and parse it.
   // Else return
   //
   File inFile = new File(Model3dIndex.getIndexPath() + "modelIndex.xml");
   // error state check
   if (inFile.exists()) {
     try {
       Model3dIndex.getListofAllMetaEntries().clear();
       FileReader tmpInReader = new FileReader(inFile);
       WstxInputFactory fin = new WstxInputFactory();
       fin.configureForConvenience();
       fin.setProperty(
           XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE); // <-- NEEDED TO GET ATTRIBUTES!
       // input
       XMLStreamReader2 sr = (XMLStreamReader2) fin.createXMLStreamReader(tmpInReader);
       SMInputCursor inputRootElement = SMInputFactory.rootElementCursor(sr);
       inputRootElement.getNext();
       SMInputCursor childInElement = inputRootElement.childCursor();
       String myText = "";
       while (childInElement.getNext() != null) {
         if (!childInElement.getCurrEvent().hasText()
             && childInElement
                 .getLocalName()
                 .toLowerCase()
                 .equals(Model3dIndex.getMetaEntryTag().toLowerCase())) {
           Model3dIndex.getListofAllMetaEntries().add(new Model3dIndexEntry(childInElement));
         }
       }
       tmpInReader.close();
     } catch (Exception e) {
       return;
     }
   } else return;
 }