List of usage examples for java.util ListIterator hasNext
boolean hasNext();
From source file:com.jaspersoft.studio.property.section.style.inerithance.StylesListSection.java
/** * Print the attributes of all the styles of the element * /*w ww . j a v a 2s .c om*/ * @param styles List of styles * @param parent composite of the main widget */ private void printStyles(LinkedList<MStyle> styles, Composite parent) { ListIterator<MStyle> itr = styles.listIterator(); boolean hasDefaultStyleInGerarchy = false; while (itr.hasNext()) { MStyle style = itr.next(); String titleLabelText = MessageFormat.format(Messages.StylesSectionList_Inherited_From_Style, new Object[] { style.getPropertyValue(JRDesignStyle.PROPERTY_NAME) }); printStyleTitle(titleLabelText, style, parent); printStyleAttribute(parent, style, null, AttributeParent.STYLE); //$NON-NLS-1$ if (style == defaultStyle) hasDefaultStyleInGerarchy = true; } //FIXME: JR has a bug where it dosen't use the default styles if the element has at least one style //unit it will be fixed, to show the effective hierarchy, the default style is print only if there //aren't other styles on the element if (styles.isEmpty() && !hasDefaultStyleInGerarchy && defaultStyle != null && defaultStyle != getElement()) { String titleLabelText = MessageFormat.format(Messages.StylesListSection_Inherited_From_Default_Style, new Object[] { defaultStyle.getPropertyValue(JRDesignStyle.PROPERTY_NAME) }); printStyleTitle(titleLabelText, defaultStyle, parent); printStyleAttribute(parent, defaultStyle, null, AttributeParent.STYLE); //$NON-NLS-1$ } }
From source file:atfrogs.ox.api.OXWebDAVApi.java
/** * Returns a list of all OXUser objects of group members of group with * given gid. You should not pass a pattern as gid. If done so you'll get * the list of OXUser objects of the group being the first search result. * /*w w w . ja v a 2 s . com*/ * @param gid the gid of group requested. * @return the list of OXUser objects. * @throws OXWebDAVApiException if an error occurs during operation. */ public List getMembersOfGroup(String gid) throws OXWebDAVApiException { List memberIdList; // of String List userList; // of OXUser ListIterator iterator; if (gid == null) return null; try { memberIdList = this.getMemberIdsOfGroup(gid); if (memberIdList == null) return null; userList = new Vector(); iterator = memberIdList.listIterator(); while (iterator.hasNext()) { String uid; OXUser user; uid = (String) iterator.next(); user = this.getOXUser(uid); userList.add(user); } } catch (Exception exc) { exc.printStackTrace(); throw new OXWebDAVApiException(exc.getMessage(), exc); } return userList; // note: may be empty }
From source file:atfrogs.ox.api.OXWebDAVApi.java
/** * Returns a list of all OXResource objects of resources in resource group * with given gid./* w ww . j a va 2s.com*/ * You should not pass a pattern as gid. If done so you'll get the * list of OXResource objects of the resource group being the first search result. * * @param gid the gid of resource group requested. * @return the list of OXUser objects. * @throws OXWebDAVApiException if an error occurs during operation. */ public List getResourcesOfResGroup(String gid) throws OXWebDAVApiException { List resourceIdList; // of String List resourceList; // of OXResource ListIterator iterator; if (gid == null) return null; try { resourceIdList = this.getResourceIdsOfResGroup(gid); if (resourceIdList == null) return null; resourceList = new Vector(); iterator = resourceIdList.listIterator(); while (iterator.hasNext()) { String uid; OXResource resource; uid = (String) iterator.next(); resource = this.getOXResource(uid); resourceList.add(resource); } } catch (Exception exc) { exc.printStackTrace(); throw new OXWebDAVApiException(exc.getMessage(), exc); } return resourceList; // note: may be empty }
From source file:com.emc.ecs.sync.target.S3Target.java
@Override public void filter(SyncObject obj) { try {/* www .j a v a 2s .c o m*/ // skip the root of the bucket since it obviously exists if ("".equals(rootKey + obj.getRelativePath())) { log.debug("Target is bucket root; skipping"); return; } // some sync objects lazy-load their metadata (i.e. AtmosSyncObject) // since this may be a timed operation, ensure it loads outside of other timed operations if (!(obj instanceof S3ObjectVersion) || !((S3ObjectVersion) obj).isDeleteMarker()) obj.getMetadata(); // Compute target key String targetKey = getTargetKey(obj); obj.setTargetIdentifier(AwsS3Util.fullPath(bucketName, targetKey)); if (includeVersions) { ListIterator<S3ObjectVersion> sourceVersions = s3Source.versionIterator((S3SyncObject) obj); ListIterator<S3ObjectVersion> targetVersions = versionIterator(obj); boolean newVersions = false, replaceVersions = false; if (force) { replaceVersions = true; } else { // special workaround for bug where objects are listed, but they have no versions if (sourceVersions.hasNext()) { // check count and etag/delete-marker to compare version chain while (sourceVersions.hasNext()) { S3ObjectVersion sourceVersion = sourceVersions.next(); if (targetVersions.hasNext()) { S3ObjectVersion targetVersion = targetVersions.next(); if (sourceVersion.isDeleteMarker()) { if (!targetVersion.isDeleteMarker()) replaceVersions = true; } else { if (targetVersion.isDeleteMarker()) replaceVersions = true; else if (!sourceVersion.getETag().equals(targetVersion.getETag())) replaceVersions = true; // different checksum } } else if (!replaceVersions) { // source has new versions, but existing target versions are ok newVersions = true; sourceVersions.previous(); // back up one putIntermediateVersions(sourceVersions, targetKey); // add any new intermediary versions (current is added below) } } if (targetVersions.hasNext()) replaceVersions = true; // target has more versions if (!newVersions && !replaceVersions) { log.info("Source and target versions are the same. Skipping {}", obj.getRelativePath()); return; } } } // something's off; must delete all versions of the object if (replaceVersions) { log.info( "[{}]: version history differs between source and target; re-placing target version history with that from source.", obj.getRelativePath()); // collect versions in target List<DeleteObjectsRequest.KeyVersion> deleteVersions = new ArrayList<>(); while (targetVersions.hasNext()) targetVersions.next(); // move cursor to end while (targetVersions.hasPrevious()) { // go in reverse order S3ObjectVersion version = targetVersions.previous(); deleteVersions.add(new DeleteObjectsRequest.KeyVersion(targetKey, version.getVersionId())); } // batch delete all versions in target log.debug("[{}]: deleting all versions in target", obj.getRelativePath()); s3.deleteObjects(new DeleteObjectsRequest(bucketName).withKeys(deleteVersions)); // replay version history in target while (sourceVersions.hasPrevious()) sourceVersions.previous(); // move cursor to beginning putIntermediateVersions(sourceVersions, targetKey); } } else { // normal sync (no versions) Date sourceLastModified = obj.getMetadata().getModificationTime(); long sourceSize = obj.getMetadata().getContentLength(); // Get target metadata. ObjectMetadata destMeta = null; try { destMeta = s3.getObjectMetadata(bucketName, targetKey); } catch (AmazonS3Exception e) { if (e.getStatusCode() != 404) throw new RuntimeException("Failed to check target key '" + targetKey + "' : " + e, e); } if (!force && obj.getFailureCount() == 0 && destMeta != null) { // Check overwrite Date destLastModified = destMeta.getLastModified(); long destSize = destMeta.getContentLength(); if (destLastModified.equals(sourceLastModified) && sourceSize == destSize) { log.info("Source and target the same. Skipping {}", obj.getRelativePath()); return; } if (destLastModified.after(sourceLastModified)) { log.info("Target newer than source. Skipping {}", obj.getRelativePath()); return; } } } // at this point we know we are going to write the object // Put [current object version] if (obj instanceof S3ObjectVersion && ((S3ObjectVersion) obj).isDeleteMarker()) { // object has version history, but is currently deleted log.debug("[{}]: deleting object in target to replicate delete marker in source.", obj.getRelativePath()); s3.deleteObject(bucketName, targetKey); } else { putObject(obj, targetKey); // if object has new metadata after the stream (i.e. encryption checksum), we must update S3 again if (obj.requiresPostStreamMetadataUpdate()) { log.debug("[{}]: updating metadata after sync as required", obj.getRelativePath()); CopyObjectRequest cReq = new CopyObjectRequest(bucketName, targetKey, bucketName, targetKey); cReq.setNewObjectMetadata(AwsS3Util.s3MetaFromSyncMeta(obj.getMetadata())); s3.copyObject(cReq); } } } catch (Exception e) { throw new RuntimeException("Failed to store object: " + e, e); } }
From source file:net.lightbody.bmp.proxy.jetty.http.HttpRequest.java
/** * Get the acceptable transfer encodings. The TE field is used to construct a list of acceptable * extension transfer codings in quality order. An empty list implies that only "chunked" is * acceptable. A null list implies that no transfer coding can be applied. * //from w w w . j ava 2s . c om * If the "trailer" coding is found in the TE field, then message trailers are enabled in any * linked response. * * @return List of codings. */ public List getAcceptableTransferCodings() { if (_dotVersion < 1) return null; if (_te != null) return _te; // Decode any TE field Enumeration tenum = getFieldValues(HttpFields.__TE, HttpFields.__separators); if (tenum != null) { // Sort the list List te = HttpFields.qualityList(tenum); int size = te.size(); // Process if something there if (size > 0) { Object acceptable = null; // remove trailer and chunked items. ListIterator iter = te.listIterator(); while (iter.hasNext()) { String coding = StringUtil .asciiToLowerCase(HttpFields.valueParameters(iter.next().toString(), null)); if (!HttpFields.__Chunked.equalsIgnoreCase(coding)) { acceptable = LazyList.ensureSize(acceptable, size); acceptable = LazyList.add(acceptable, coding); } } _te = LazyList.getList(acceptable); } else _te = Collections.EMPTY_LIST; } else _te = Collections.EMPTY_LIST; return _te; }
From source file:com.jaspersoft.studio.property.section.style.StylesListSection.java
/** * Print the attributes of all the styles of the element * // www. j av a 2 s . c o m * @param styles * List of styles * @param parent * composite of the main widget */ private void printStyles(LinkedList<MStyle> styles, Composite parent) { ListIterator<MStyle> itr = styles.listIterator(); boolean hasDefaultStyleInGerarchy = false; while (itr.hasNext()) { MStyle style = itr.next(); printStyleAttribute(parent, style, Messages.StylesSectionList_Inherited_From_Style + style.getPropertyValue(JRDesignStyle.PROPERTY_NAME), "", elementAttributes, true); //$NON-NLS-1$ if (style == defaultStyle) hasDefaultStyleInGerarchy = true; } if (!hasDefaultStyleInGerarchy && defaultStyle != null && defaultStyle != getElement()) printStyleAttribute(parent, defaultStyle, Messages.StylesListSection_Inherited_From_Default_Style .concat(defaultStyle.getPropertyValue(JRDesignStyle.PROPERTY_NAME).toString()), "", elementAttributes, true); //$NON-NLS-1$ //$NON-NLS-2$ }
From source file:io.swagger.codegen.languages.AbstractJavaCodegen.java
@Override public Map<String, Object> postProcessModels(Map<String, Object> objs) { // recursively add import for mapping one type to multiple imports List<Map<String, String>> recursiveImports = (List<Map<String, String>>) objs.get("imports"); if (recursiveImports == null) return objs; ListIterator<Map<String, String>> listIterator = recursiveImports.listIterator(); while (listIterator.hasNext()) { String _import = listIterator.next().get("import"); // if the import package happens to be found in the importMapping (key) // add the corresponding import package to the list if (importMapping.containsKey(_import)) { Map<String, String> newImportMap = new HashMap<String, String>(); newImportMap.put("import", importMapping.get(_import)); listIterator.add(newImportMap); }//from w ww. j av a 2 s. c o m } return postProcessModelsEnum(objs); }
From source file:annis.dao.SpringAnnisDao.java
@Override public List<AnnisBinaryMetaData> getBinaryMeta(String toplevelCorpusName, String corpusName) { List<AnnisBinaryMetaData> metaData = getJdbcTemplate().query(MetaByteHelper.SQL, metaByteHelper.getArgs(toplevelCorpusName, corpusName), MetaByteHelper.getArgTypes(), metaByteHelper);//from w ww .j av a 2s. c o m // get the file size from the real file ListIterator<AnnisBinaryMetaData> it = metaData.listIterator(); while (it.hasNext()) { AnnisBinaryMetaData singleEntry = it.next(); File f = new File(getRealDataDir(), singleEntry.getLocalFileName()); singleEntry.setLength((int) f.length()); } return metaData; }
From source file:io.bibleget.BibleGetDB.java
public boolean initialize() { try {//from ww w . j a va2s .c o m instance.conn = DriverManager.getConnection("jdbc:derby:BIBLEGET;create=true", "bibleget", "bibleget"); if (instance.conn == null) { System.out.println("Careful there! Connection not established! BibleGetDB.java line 81"); } else { System.out.println("conn is not null, which means a connection was correctly established."); } DatabaseMetaData dbMeta; dbMeta = instance.conn.getMetaData(); try (ResultSet rs1 = dbMeta.getTables(null, null, "OPTIONS", null)) { if (rs1.next()) { //System.out.println("Table "+rs1.getString("TABLE_NAME")+" already exists !!"); listColNamesTypes(dbMeta, rs1); } else { //System.out.println("Table OPTIONS does not yet exist, now attempting to create..."); try (Statement stmt = instance.conn.createStatement()) { String defaultFont = ""; if (SystemUtils.IS_OS_WINDOWS) { defaultFont = "Times New Roman"; } else if (SystemUtils.IS_OS_MAC_OSX) { defaultFont = "Helvetica"; } else if (SystemUtils.IS_OS_LINUX) { defaultFont = "Arial"; } String tableCreate = "CREATE TABLE OPTIONS (" + "PARAGRAPHALIGNMENT VARCHAR(15), " + "PARAGRAPHLINESPACING INT, " + "PARAGRAPHFONTFAMILY VARCHAR(50), " + "PARAGRAPHLEFTINDENT INT, " + "TEXTCOLORBOOKCHAPTER VARCHAR(15), " + "BGCOLORBOOKCHAPTER VARCHAR(15), " + "BOLDBOOKCHAPTER BOOLEAN, " + "ITALICSBOOKCHAPTER BOOLEAN, " + "UNDERSCOREBOOKCHAPTER BOOLEAN, " + "FONTSIZEBOOKCHAPTER INT, " + "VALIGNBOOKCHAPTER VARCHAR(15), " + "TEXTCOLORVERSENUMBER VARCHAR(15), " + "BGCOLORVERSENUMBER VARCHAR(15), " + "BOLDVERSENUMBER BOOLEAN, " + "ITALICSVERSENUMBER BOOLEAN, " + "UNDERSCOREVERSENUMBER BOOLEAN, " + "FONTSIZEVERSENUMBER INT, " + "VALIGNVERSENUMBER VARCHAR(15), " + "TEXTCOLORVERSETEXT VARCHAR(15), " + "BGCOLORVERSETEXT VARCHAR(15), " + "BOLDVERSETEXT BOOLEAN, " + "ITALICSVERSETEXT BOOLEAN, " + "UNDERSCOREVERSETEXT BOOLEAN, " + "FONTSIZEVERSETEXT INT, " + "VALIGNVERSETEXT VARCHAR(15), " + "PREFERREDVERSIONS VARCHAR(50), " + "NOVERSIONFORMATTING BOOLEAN" + ")"; String tableInsert; tableInsert = "INSERT INTO OPTIONS (" + "PARAGRAPHALIGNMENT," + "PARAGRAPHLINESPACING," + "PARAGRAPHFONTFAMILY," + "PARAGRAPHLEFTINDENT," + "TEXTCOLORBOOKCHAPTER," + "BGCOLORBOOKCHAPTER," + "BOLDBOOKCHAPTER," + "ITALICSBOOKCHAPTER," + "UNDERSCOREBOOKCHAPTER," + "FONTSIZEBOOKCHAPTER," + "VALIGNBOOKCHAPTER," + "TEXTCOLORVERSENUMBER," + "BGCOLORVERSENUMBER," + "BOLDVERSENUMBER," + "ITALICSVERSENUMBER," + "UNDERSCOREVERSENUMBER," + "FONTSIZEVERSENUMBER," + "VALIGNVERSENUMBER," + "TEXTCOLORVERSETEXT," + "BGCOLORVERSETEXT," + "BOLDVERSETEXT," + "ITALICSVERSETEXT," + "UNDERSCOREVERSETEXT," + "FONTSIZEVERSETEXT," + "VALIGNVERSETEXT," + "PREFERREDVERSIONS, " + "NOVERSIONFORMATTING" + ") VALUES (" + "'justify',100,'" + defaultFont + "',0," + "'#0000FF','#FFFFFF',true,false,false,14,'initial'," + "'#AA0000','#FFFFFF',false,false,false,10,'super'," + "'#696969','#FFFFFF',false,false,false,12,'initial'," + "'NVBSE'," + "false" + ")"; boolean tableCreated = stmt.execute(tableCreate); boolean rowsInserted; int count; if (tableCreated == false) { //is false when it's an update count! count = stmt.getUpdateCount(); if (count == -1) { //System.out.println("The result is a ResultSet object or there are no more results."); } else { //this is our expected behaviour: 0 rows affected //System.out.println("The Table Creation statement produced results: "+count+" rows affected."); try (Statement stmt2 = instance.conn.createStatement()) { rowsInserted = stmt2.execute(tableInsert); if (rowsInserted == false) { count = stmt2.getUpdateCount(); if (count == -1) { //System.out.println("The result is a ResultSet object or there are no more results."); } else { //this is our expected behaviour: n rows affected //System.out.println("The Row Insertion statement produced results: "+count+" rows affected."); dbMeta = instance.conn.getMetaData(); try (ResultSet rs2 = dbMeta.getTables(null, null, "OPTIONS", null)) { if (rs2.next()) { listColNamesTypes(dbMeta, rs2); } rs2.close(); } } } else { //is true when it returns a resultset, which shouldn't be the case here try (ResultSet rx = stmt2.getResultSet()) { while (rx.next()) { //System.out.println("This isn't going to happen anyways, so..."); } rx.close(); } } stmt2.close(); } } } else { //is true when it returns a resultset, which shouldn't be the case here try (ResultSet rx = stmt.getResultSet()) { while (rx.next()) { //System.out.println("This isn't going to happen anyways, so..."); } rx.close(); } } stmt.close(); } } rs1.close(); } //System.out.println("Finished with first ResultSet resource, now going on to next..."); try (ResultSet rs3 = dbMeta.getTables(null, null, "METADATA", null)) { if (rs3.next()) { //System.out.println("Table "+rs3.getString("TABLE_NAME")+" already exists !!"); } else { //System.out.println("Table METADATA does not exist, now attempting to create..."); try (Statement stmt = instance.conn.createStatement()) { String tableCreate = "CREATE TABLE METADATA ("; tableCreate += "ID INT, "; for (int i = 0; i < 73; i++) { tableCreate += "BIBLEBOOKS" + Integer.toString(i) + " VARCHAR(2000), "; } tableCreate += "LANGUAGES VARCHAR(500), "; tableCreate += "VERSIONS VARCHAR(2000)"; tableCreate += ")"; boolean tableCreated = stmt.execute(tableCreate); boolean rowsInserted; int count; if (tableCreated == false) { //this is the expected result, is false when it's an update count! count = stmt.getUpdateCount(); if (count == -1) { //System.out.println("The result is a ResultSet object or there are no more results."); } else { //this is our expected behaviour: 0 rows affected //System.out.println("The Table Creation statement produced results: "+count+" rows affected."); //Insert a dummy row, because you cannot update what has not been inserted! try (Statement stmtX = instance.conn.createStatement()) { stmtX.execute("INSERT INTO METADATA (ID) VALUES (0)"); stmtX.close(); } HTTPCaller myHTTPCaller = new HTTPCaller(); String myResponse; myResponse = myHTTPCaller.getMetaData("biblebooks"); if (myResponse != null) { JsonReader jsonReader = Json.createReader(new StringReader(myResponse)); JsonObject json = jsonReader.readObject(); JsonArray arrayJson = json.getJsonArray("results"); if (arrayJson != null) { ListIterator pIterator = arrayJson.listIterator(); while (pIterator.hasNext()) { try (Statement stmt2 = instance.conn.createStatement()) { int index = pIterator.nextIndex(); JsonArray currentJson = (JsonArray) pIterator.next(); String biblebooks_str = currentJson.toString(); //.replaceAll("\"", "\\\\\""); //System.out.println("BibleGetDB line 267: BIBLEBOOKS"+Integer.toString(index)+"='"+biblebooks_str+"'"); String stmt_str = "UPDATE METADATA SET BIBLEBOOKS" + Integer.toString(index) + "='" + biblebooks_str + "' WHERE ID=0"; try { //System.out.println("executing update: "+stmt_str); int update = stmt2.executeUpdate(stmt_str); //System.out.println("executeUpdate resulted in: "+Integer.toString(update)); } catch (SQLException ex) { Logger.getLogger(BibleGetDB.class.getName()).log(Level.SEVERE, null, ex); } stmt2.close(); } } } arrayJson = json.getJsonArray("languages"); if (arrayJson != null) { try (Statement stmt2 = instance.conn.createStatement()) { String languages_str = arrayJson.toString(); //.replaceAll("\"", "\\\\\""); String stmt_str = "UPDATE METADATA SET LANGUAGES='" + languages_str + "' WHERE ID=0"; try { int update = stmt2.executeUpdate(stmt_str); } catch (SQLException ex) { Logger.getLogger(BibleGetDB.class.getName()).log(Level.SEVERE, null, ex); } stmt2.close(); } } } myResponse = myHTTPCaller.getMetaData("bibleversions"); if (myResponse != null) { JsonReader jsonReader = Json.createReader(new StringReader(myResponse)); JsonObject json = jsonReader.readObject(); JsonObject objJson = json.getJsonObject("validversions_fullname"); if (objJson != null) { String bibleversions_str = objJson.toString(); //.replaceAll("\"", "\\\\\""); try (Statement stmt2 = instance.conn.createStatement()) { String stmt_str = "UPDATE METADATA SET VERSIONS='" + bibleversions_str + "' WHERE ID=0"; try { int update = stmt2.executeUpdate(stmt_str); } catch (SQLException ex) { Logger.getLogger(BibleGetDB.class.getName()).log(Level.SEVERE, null, ex); } stmt2.close(); } Set<String> versionsabbrev = objJson.keySet(); if (!versionsabbrev.isEmpty()) { String versionsabbrev_str = ""; for (String s : versionsabbrev) { versionsabbrev_str += ("".equals(versionsabbrev_str) ? "" : ",") + s; } myResponse = myHTTPCaller .getMetaData("versionindex&versions=" + versionsabbrev_str); if (myResponse != null) { jsonReader = Json.createReader(new StringReader(myResponse)); json = jsonReader.readObject(); objJson = json.getJsonObject("indexes"); if (objJson != null) { for (String name : objJson.keySet()) { JsonObjectBuilder tempBld = Json.createObjectBuilder(); JsonObject book_num = objJson.getJsonObject(name); tempBld.add("book_num", book_num.getJsonArray("book_num")); tempBld.add("chapter_limit", book_num.getJsonArray("chapter_limit")); tempBld.add("verse_limit", book_num.getJsonArray("verse_limit")); JsonObject temp = tempBld.build(); String versionindex_str = temp.toString(); //.replaceAll("\"", "\\\\\""); //add new column to METADATA table name+"IDX" VARCHAR(5000) //update METADATA table SET name+"IDX" = versionindex_str try (Statement stmt3 = instance.conn.createStatement()) { String sql = "ALTER TABLE METADATA ADD COLUMN " + name + "IDX VARCHAR(5000)"; boolean colAdded = stmt3.execute(sql); if (colAdded == false) { count = stmt3.getUpdateCount(); if (count == -1) { //System.out.println("The result is a ResultSet object or there are no more results."); } else if (count == 0) { //0 rows affected stmt3.close(); try (Statement stmt4 = instance.conn .createStatement()) { String sql1 = "UPDATE METADATA SET " + name + "IDX='" + versionindex_str + "' WHERE ID=0"; boolean rowsUpdated = stmt4.execute(sql1); if (rowsUpdated == false) { count = stmt4.getUpdateCount(); if (count == -1) { //System.out.println("The result is a ResultSet object or there are no more results."); } else { //should have affected only one row if (count == 1) { //System.out.println(sql1+" seems to have returned true"); stmt4.close(); } } } else { //returns true only when returning a resultset; should not be the case here } } } } else { //returns true only when returning a resultset; should not be the case here } stmt3.close(); } } } } } } } } } else { //is true when it returns a resultset, which shouldn't be the case here ResultSet rx = stmt.getResultSet(); while (rx.next()) { //System.out.println("This isn't going to happen anyways, so..."); } } stmt.close(); } } rs3.close(); } instance.conn.close(); return true; } catch (SQLException ex) { if (ex.getSQLState().equals("X0Y32")) { Logger.getLogger(BibleGetDB.class.getName()).log(Level.INFO, null, "Table OPTIONS or Table METADATA already exists. No need to recreate"); return true; } else if (ex.getNextException().getErrorCode() == 45000) { //this means we already have a connection, so this is good too return true; } else { //Logger.getLogger(BibleGetDB.class.getName()).log(Level.SEVERE, null, ex.getMessage() + " : " + Arrays.toString(ex.getStackTrace())); Logger.getLogger(BibleGetDB.class.getName()).log(Level.SEVERE, null, ex); return false; } } }
From source file:com.edgenius.wiki.render.filter.LinkFilter.java
/** * Accept <a> or <object file="*"> tags *///from w ww.j a va 2 s. c o m @Override protected void replaceHTML(HTMLNode node, ListIterator<HTMLNode> nodeIter, RenderContext context) { if (node.getPair() == null || node.getAttributes() == null) { AuditLogger.error("Unexpected case: Unable to find close </a> tag"); return; } Map<String, String> atts = node.getAttributes(); if (atts.get(NameConstants.AID) != null //this is special checking for Safari browser, it remove all other attributes if it has "name" attribute. || (atts.size() == 1 && atts.containsKey(NameConstants.NAME))) { //default link filter won't have "aid" - it should be anchor return; } StringBuffer viewSb = new StringBuffer(); //whatever internal(wajax) or external link, view always parse out from tag surrounded text HTMLNode cursor = node; boolean hasStyleNode = false; for (; nodeIter.hasNext() && cursor != node.getPair(); cursor = nodeIter.next()) { if (cursor.isTextNode()) { viewSb.append(cursor.getText()); } else { hasStyleNode = true; } } LinkModel link = new LinkModel(); if ("object".equals(node.getTagName())) { //pattern ensure it must has "data" attribute String fileURL = node.getAttributes().get("data"); //must root file i.e., file:///myfile.txt if (!StringUtils.startsWith(fileURL, "file:///")) { log.warn("Object type link has invalid URL {}", fileURL); return; } fileURL = fileURL.substring(8); //if it has "/" means it is possible file:///c:/document/myfile.txt format, ignore it if (StringUtils.isBlank(fileURL) || fileURL.indexOf("/") != -1) { log.warn("Object type link is not root file {}", fileURL); return; } link.setLink(fileURL); link.setView(viewSb.toString()); link.setType(LinkModel.LINK_TO_ATTACHMENT); } else { link.fillToObject(node.getText(), viewSb.toString()); if (LinkUtil.isAttachmentLink(link.getLink())) { link.setType(LinkModel.LINK_TO_ATTACHMENT); link.setLink(StringEscapeUtils.unescapeHtml(LinkUtil.getAttachmentFile(link.getLink()))); } } //as link may contain some style mark up, such as [th%%*is is b*%%old>view], so here won't process view //but only if view==link and view is only TextNode, I will reset view TextNode at this case node.reset("[", true); //this endMarkup only include the part after "view", such as ">link@space]". The part before that "[view" is handled above StringBuffer endMarkup = new StringBuffer(); //only the link is not equals view, [view>link] needs display "view" part String escapedLink = EscapeUtil.escapeMarkupLink(link.getLink()); if (!hasStyleNode || !StringUtils.equals(link.getView(), escapedLink)) { endMarkup.append(">"); } else { //clean embedded text of link, as view == link, don't need display cursor = node.next(); for (; cursor != null && cursor != node.getPair(); cursor = cursor.next()) { cursor.reset("", true); } } if (!StringUtils.isBlank(link.getLink())) { if (link.getType() == LinkModel.LINK_TO_ATTACHMENT) { endMarkup.append("^"); } endMarkup.append(escapedLink); } if (!StringUtils.isBlank(link.getAnchor())) { endMarkup.append("#").append(link.getAnchor()); } //only different space, append spaceUname to link if (!StringUtils.isBlank(link.getSpaceUname()) && !StringUtils.equalsIgnoreCase(link.getSpaceUname(), context.getSpaceUname())) { endMarkup.append("@").append(link.getSpaceUname()); } endMarkup.append("]"); node.getPair().reset(endMarkup.toString(), true); }