/** * Gets the persistent IDs of the documents in this corpus. * * @return a {@link List} of Objects representing the persistent IDs of the documents in this * corpus. */ public List<String> getDocumentClassTypes() { List<String> docsIDs = new ArrayList<String>(); if (docDataList == null) return docsIDs; Iterator<DocumentData> iter = docDataList.iterator(); while (iter.hasNext()) { DocumentData data = iter.next(); docsIDs.add(data.getClassType()); } return docsIDs; }
/** * Gets the persistent IDs of the documents in this corpus. * * @return a {@link List} of Objects representing the persistent IDs of the documents in this * corpus. */ public List<Object> getDocumentPersistentIDs() { List<Object> docsIDs = new ArrayList<Object>(); if (docDataList == null) return docsIDs; Iterator<DocumentData> iter = docDataList.iterator(); while (iter.hasNext()) { DocumentData data = iter.next(); docsIDs.add(data.getPersistentID()); } return docsIDs; }
/** * Gets the names of the documents in this corpus. * * @return a {@link List} of Strings representing the names of the documents in this corpus. */ @Override public List<String> getDocumentNames() { List<String> docsNames = new ArrayList<String>(); if (docDataList == null) return docsNames; for (Object aDocDataList : docDataList) { DocumentData data = (DocumentData) aDocDataList; docsNames.add(data.getDocumentName()); } return docsNames; }
/** Called by a datastore when a resource has been deleted */ @Override public void resourceDeleted(DatastoreEvent evt) { DataStore ds = (DataStore) evt.getSource(); // 1. check whether this datastore fired the event. If not, return. if (!ds.equals(this.dataStore)) return; Object docID = evt.getResourceID(); if (docID == null) return; if (DEBUG) Out.prln("Resource deleted called for: " + docID); // first check if it is this corpus that's been deleted, it must be // unloaded immediately if (docID.equals(this.getLRPersistenceId())) { Factory.deleteResource(this); return; } // if boolean isDirty = false; // the problem here is that I only have the doc persistent ID // and nothing else, so I need to determine the index of the doc // first for (int i = 0; i < docDataList.size(); i++) { DocumentData docData = docDataList.get(i); // we've found the correct document // don't break the loop, because it might appear more than once if (docID.equals(docData.getPersistentID())) { if (evt.getResource() == null) { // instead of calling remove() which tries to load the // document // remove it from the documents and docDataList documentRemoved(docDataList.get(i).persistentID.toString()); docDataList.remove(i); documents.remove(i); isDirty = true; i--; continue; } remove(i); isDirty = true; } // if } // for loop through the doc data if (isDirty) try { this.dataStore.sync(this); } catch (PersistenceException ex) { throw new GateRuntimeException("SerialCorpusImpl: " + ex.getMessage()); } catch (SecurityException sex) { throw new GateRuntimeException("SerialCorpusImpl: " + sex.getMessage()); } } // resourceDeleted
/** * Crea un XML con la información necesaria para la previsualización de un * documento. * * @param docData Datos del documento. * @return XML con la información del documento. */ static String createPreviewResponse(final DocumentData docData) { final StringBuilder sb = new StringBuilder(); sb.append(XML_HEADER); sb.append("<prw docid=\"") .append(docData.getDocId()) .append("\">"); // $NON-NLS-1$ //$NON-NLS-2$ sb.append("<name>") .append(docData.getFilename()) .append("</name>"); // $NON-NLS-1$ //$NON-NLS-2$ sb.append("<mmtp>") .append(docData.getMimetype()) .append("</mmtp>"); // $NON-NLS-1$ //$NON-NLS-2$ sb.append("<data>").append(docData.getDataB64()).append("</data>"); // $NON-NLS-1$ //$NON-NLS-2$ sb.append("</prw>"); // $NON-NLS-1$ return sb.toString(); }
public int findDocument(Document doc) { boolean found = false; DocumentData docData = null; // first try finding the document in memory int index = documents.indexOf(doc); if (index > -1 && index < docDataList.size()) return index; // else try finding a document with the same name and persistent ID Iterator<DocumentData> iter = docDataList.iterator(); for (index = 0; iter.hasNext(); index++) { docData = iter.next(); if (docData.getDocumentName().equals(doc.getName()) && docData.getPersistentID().equals(doc.getLRPersistenceId()) && docData.getClassType().equals(doc.getClass().getName())) { found = true; break; } } if (found && index < docDataList.size()) return index; else return -1; } // findDocument
protected void fromXML(DOMReaderHelper rd) throws IOException { rd.getChild(); ///////////////////////////////////////////////////////////////////////////////////////// // Get the signature profile response [1] ///////////////////////////////////////////////////////////////////////////////////////// sign_prof_data = (SignatureProfileResponseDecoder) wrap(rd.getNext()); ///////////////////////////////////////////////////////////////////////////////////////// // Get the optional document data [0..1] ///////////////////////////////////////////////////////////////////////////////////////// if (rd.hasNext(DocumentData.DOCUMENT_DATA_ELEM)) { doc_data = DocumentData.read(rd); } }