/** * Returns the file identifier of of the file containing the object. * * @return the file identifier of of the file containing the object. */ public final long getFID() { if (fileFormat != null) { return fileFormat.getFID(); } else { return -1; } }
/** * New instance of {@link OGRFeatureWriter} * * @param progressListener * @param schema output schema * @param basedir output folder * @param fileFormat output fileExtension * @param features input the set of Features to write */ public OGRFeatureWriter( ProgressListener progressListener, SimpleFeatureType schema, File basedir, FileFormat fileFormat, SimpleFeatureCollection features) { assert schema != null && basedir != null && features != null; this.progresListener = progresListener; this.schema = schema; this.basedir = basedir; this.fileFormat = fileFormat; this.options = fileFormat.getFormatOptions(); this.features = features; }
@Test public void testFileRead() { SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd"); ConfigurationReader parser = new ConfigurationReader(); try { FileFormat ff = parser.loadConfigurationFile("complex-example.xml"); InputStream in = new FileInputStream("../test/resources/complex_input.txt"); BufferedReader bufIn = new BufferedReader(new InputStreamReader(in)); MatchedRecord results = ff.getNextRecord(bufIn); assertEquals("dvd", results.getRecordName()); Dvd dvd = (Dvd) results.getBean("dvd"); Film film = (Film) results.getBean("film"); assertEquals("55512121", dvd.getSku()); assertEquals(49.95, dvd.getPrice(), 0.01); assertEquals("Y", dvd.getDualLayer()); assertEquals("2004/01/15", format.format(film.getReleaseDate())); assertEquals("DIAL J FOR JAVA", film.getTitle()); assertEquals("RUN ANYWHERE STUDIO", film.getStudio()); results = ff.getNextRecord(bufIn); assertEquals("book", results.getRecordName()); Book book = (Book) results.getBean("book"); assertEquals("546234476", book.getSku()); assertEquals("HE KNOWS WHEN YOU\"RE CODING", book.getTitle()); assertEquals("JAVALANG OBJECT", book.getAuthor()); assertEquals(13.95, book.getPrice(), 0.01); assertEquals("2003/11/10", format.format(book.getReleaseDate())); results = ff.getNextRecord(bufIn); assertEquals("videotape", results.getRecordName()); Videotape tape = (Videotape) results.getBean("video"); film = (Film) results.getBean("film"); assertEquals("2346542", tape.getSku()); assertEquals(23.55, tape.getPrice(), 0.01); assertEquals("2003/03/12", format.format(film.getReleaseDate())); assertEquals("WHEN A STRANGER IMPLEMENTS", film.getTitle()); assertEquals("NULL POINTER PRODUCTIONS", film.getStudio()); results = ff.getNextRecord(bufIn); assertEquals("book", results.getRecordName()); results = ff.getNextRecord(bufIn); assertEquals("videotape", results.getRecordName()); } catch (Exception e) { fail("Caught an exception of type " + e.getClass().getSimpleName()); } }
/** * @deprecated Not for public use in the future.<br> * Using {@link #HObject(FileFormat, String, String)} */ @Deprecated public HObject(FileFormat theFile, String theName, String thePath, long[] oid) { this.fileFormat = theFile; this.oid = oid; if (fileFormat != null) { this.filename = fileFormat.getFilePath(); } else { this.filename = null; } // file name is packed in the full path if ((theName == null) && (thePath != null)) { if (thePath.equals(separator)) { theName = separator; thePath = null; } else { // the path must starts with "/" if (!thePath.startsWith(HObject.separator)) { thePath = HObject.separator + thePath; } // get rid of the last "/" if (thePath.endsWith(HObject.separator)) { thePath = thePath.substring(0, thePath.length() - 1); } // seperate the name and the path theName = thePath.substring(thePath.lastIndexOf(separator) + 1); thePath = thePath.substring(0, thePath.lastIndexOf(separator)); } } else if ((theName != null) && (thePath == null) && (theName.indexOf(separator) >= 0)) { if (theName.equals(separator)) { theName = separator; thePath = null; } else { // the full name must starts with "/" if (!theName.startsWith(separator)) { theName = separator + theName; } // the fullname must not end with "/" int n = theName.length(); if (theName.endsWith(separator)) { theName = theName.substring(0, n - 1); } int idx = theName.lastIndexOf(separator); if (idx < 0) { thePath = separator; } else { thePath = theName.substring(0, idx); theName = theName.substring(idx + 1); } } } // the path must start and end with "/" if (thePath != null) { thePath = thePath.replaceAll("//", "/"); if (!thePath.endsWith(separator)) { thePath += separator; } } this.name = theName; this.path = thePath; if (thePath != null) { this.fullName = thePath + theName; } else { if (theName == null) { this.fullName = "/"; } else if (theName.startsWith("/")) { this.fullName = theName; } else { this.fullName = "/" + theName; } } }
private Object traverse(Node node) throws FlatwormUnsetFieldValueException, FlatwormConfigurationValueException { int type = node.getNodeType(); if (type == Node.ELEMENT_NODE) { String nodeName = node.getNodeName(); if (nodeName.equals("file-format")) { FileFormat f = new FileFormat(); String encoding = Charset.defaultCharset().name(); if (hasAttributeValueNamed(node, "encoding")) { encoding = getAttributeValueNamed(node, "encoding"); } f.setEncoding(encoding); List<Object> children = getChildNodes(node); for (int i = 0; i < children.size(); i++) { if (children.get(i).getClass().equals(Converter.class)) { f.addConverter((Converter) children.get(i)); } if (children.get(i).getClass().equals(Record.class)) { f.addRecord((Record) children.get(i)); } } return f; } if (nodeName.equals("converter")) { Converter c = new Converter(); c.setConverterClass(getAttributeValueNamed(node, "class")); c.setMethod(getAttributeValueNamed(node, "method")); c.setReturnType(getAttributeValueNamed(node, "return-type")); c.setName(getAttributeValueNamed(node, "name")); return c; } if (nodeName.equals("record")) { Record r = new Record(); r.setName(getAttributeValueNamed(node, "name")); Node identChild = getChildElementNodeOfType("record-ident", node); if (identChild != null) { Node fieldChild = getChildElementNodeOfType("field-ident", identChild); Node lengthChild = getChildElementNodeOfType("length-ident", identChild); if (lengthChild != null) { r.setLengthIdentMin(Integer.parseInt(getAttributeValueNamed(lengthChild, "minlength"))); r.setLengthIdentMax(Integer.parseInt(getAttributeValueNamed(lengthChild, "maxlength"))); r.setIdentTypeFlag('L'); } else if (fieldChild != null) { r.setFieldIdentStart( Integer.parseInt(getAttributeValueNamed(fieldChild, "field-start"))); r.setFieldIdentLength( Integer.parseInt(getAttributeValueNamed(fieldChild, "field-length"))); List<Node> matchNodes = getChildElementNodesOfType("match-string", fieldChild); for (int j = 0; j < matchNodes.size(); j++) { r.addFieldIdentMatchString(getChildTextNodeValue(matchNodes.get(j))); } r.setIdentTypeFlag('F'); } } Node recordChild = getChildElementNodeOfType("record-definition", node); r.setRecordDefinition((RecordDefinition) traverse(recordChild)); return r; } if (nodeName.equals("record-definition")) { RecordDefinition rd = new RecordDefinition(); List<Object> children = getChildNodes(node); for (int i = 0; i < children.size(); i++) { Object o = children.get(i); if (o.getClass().equals(Bean.class)) { rd.addBeanUsed((Bean) o); } if (o.getClass().equals(Line.class)) { rd.addLine((Line) o); } } return rd; } if (nodeName.equals("bean")) { Bean b = new Bean(); b.setBeanName(getAttributeValueNamed(node, "name")); b.setBeanClass(getAttributeValueNamed(node, "class")); try { b.setBeanObjectClass(Class.forName(b.getBeanClass())); } catch (ClassNotFoundException e) { throw new FlatwormConfigurationValueException("Unable to load class " + b.getBeanClass()); } return b; } if (nodeName.equals("line")) { Line li = new Line(); // JBL - Determine if this line is delimited // Determine value of quote character, default = " // These field is optional Node delimit = getAttributeNamed(node, "delimit"); Node quote = getAttributeNamed(node, "quote"); if (delimit != null) { li.setDelimeter(getAttributeValueNamed(node, "delimit")); } if (quote != null) { li.setQuoteChar(getAttributeValueNamed(node, "quote")); } List<Object> v = getChildNodes(node); for (int i = 0; i < v.size(); i++) { Object o = v.get(i); if (o instanceof LineElement) { li.addElement((LineElement) o); } } return li; } if (nodeName.equals("segment-element")) { SegmentElement segment = new SegmentElement(); segment.setCardinalityMode(CardinalityMode.LOOSE); segment.setName(getAttributeValueNamed(node, "name")); segment.setMinCount(Integer.parseInt(getAttributeValueNamed(node, "minCount"))); segment.setMaxCount(Integer.parseInt(getAttributeValueNamed(node, "maxCount"))); segment.setBeanRef(getAttributeValueNamed(node, "beanref")); segment.setParentBeanRef(getAttributeValueNamed(node, "parent-beanref")); segment.setAddMethod(getAttributeValueNamed(node, "addMethod")); String segmentMode = getAttributeValueNamed(node, "cardinality-mode"); if (!StringUtils.isBlank(segmentMode)) { if (segmentMode.toLowerCase().startsWith("strict")) { segment.setCardinalityMode(CardinalityMode.STRICT); } else if (segmentMode.toLowerCase().startsWith("restrict")) { segment.setCardinalityMode(CardinalityMode.RESTRICTED); } } Node fieldChild = getChildElementNodeOfType("field-ident", node); if (fieldChild != null) { segment.setFieldIdentStart( Integer.parseInt(getAttributeValueNamed(fieldChild, "field-start"))); segment.setFieldIdentLength( Integer.parseInt(getAttributeValueNamed(fieldChild, "field-length"))); List<Node> matchNodes = getChildElementNodesOfType("match-string", fieldChild); for (int j = 0; j < matchNodes.size(); j++) { segment.addFieldIdentMatchString(getChildTextNodeValue((Node) matchNodes.get(j))); } } validateSegmentConfiguration(segment); List<Object> v = getChildNodes(node); for (int i = 0; i < v.size(); i++) { Object o = v.get(i); if (o instanceof LineElement) { segment.addElement((LineElement) o); } } return segment; } if (nodeName.equals("record-element")) { RecordElement re = new RecordElement(); Node start = getAttributeNamed(node, "start"); Node end = getAttributeNamed(node, "end"); Node length = getAttributeNamed(node, "length"); Node beanref = getAttributeNamed(node, "beanref"); Node beanType = getAttributeNamed(node, "type"); if ((end == null) && (length == null)) { FlatwormConfigurationValueException err = new FlatwormConfigurationValueException( "Must set either the 'end' or 'length' properties"); throw err; } if ((end != null) && (length != null)) { FlatwormConfigurationValueException err = new FlatwormConfigurationValueException( "Can't specify both the 'end' or 'length' properties"); throw err; } if (start != null) { re.setFieldStart(Integer.parseInt(start.getNodeValue())); } if (end != null) { re.setFieldEnd(Integer.parseInt(end.getNodeValue())); } if (length != null) { re.setFieldLength(Integer.parseInt(length.getNodeValue())); } if (beanref != null) { re.setBeanRef(beanref.getNodeValue()); } if (beanType != null) { re.setType(beanType.getNodeValue()); } List<Node> children = getChildElementNodesOfType("conversion-option", node); for (int i = 0; i < children.size(); i++) { Node o = (Node) children.get(i); String name = getAttributeValueNamed(o, "name"); String value = getAttributeValueNamed(o, "value"); ConversionOption co = new ConversionOption(name, value); re.addConversionOption(name, co); } return re; } } return null; }