List of usage examples for java.lang Byte parseByte
public static byte parseByte(String s) throws NumberFormatException
From source file:forseti.contabilidad.JContaPolizasDlg.java
public void EditarPartida(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { short idmensaje = -1; StringBuffer mensaje = new StringBuffer(254); HttpSession ses = request.getSession(true); JContaPolizasSes pol = (JContaPolizasSes) ses.getAttribute("conta_polizas_dlg"); double debe = (request.getParameter("debe") != null && !request.getParameter("debe").equals("")) ? Float.parseFloat(request.getParameter("debe")) : 0F;/*from w w w . j a va 2 s . c om*/ double haber = (request.getParameter("haber") != null && !request.getParameter("haber").equals("")) ? Float.parseFloat(request.getParameter("haber")) : 0F; double tc = Float.parseFloat(request.getParameter("tc")); byte idmoneda = Byte.parseByte(request.getParameter("idmoneda")); idmensaje = pol.editaPartida(Integer.parseInt(request.getParameter("idpartida")), request, JUtil.obtCuentas(request.getParameter("cuenta"), (byte) 19), pt(request.getParameter("concepto_part")), idmoneda, tc, debe, haber, mensaje); getSesion(request).setID_Mensaje(idmensaje, mensaje.toString()); }
From source file:edu.ku.brc.specify.conversion.ConvertVerifier.java
/** * @param oldNewIdStr/*from w ww.jav a 2 s .c o m*/ * @param newColInx * @param oldColInx * @return * @throws SQLException */ private StatusType compareDates(final String oldNewIdStr, final int newColInx, final int oldColInx) throws SQLException { PartialDateConv datePair = new PartialDateConv(); Object newObj = newDBRS.getObject(newColInx); Object oldObj = oldDBRS.getObject(oldColInx); ResultSetMetaData newRsmd = newDBRS.getMetaData(); ResultSetMetaData oldRsmd = oldDBRS.getMetaData(); String newColName = newRsmd.getColumnName(newColInx); String oldColName = oldRsmd.getColumnName(oldColInx); if (newObj == null) { String clsName = newRsmd.getColumnClassName(newColInx); if (compareTo6DBs) { if (!clsName.equals("java.sql.Date") || oldObj != null) { String msg = "New Value was null and shouldn't have been for Key Value New Field [" + newColName + "] [" + oldObj + "]"; log.error(msg); tblWriter.logErrors(newColName, msg); return StatusType.NEW_VAL_NULL; } } else if (oldObj != null) { if (oldObj instanceof Number && ((Number) oldObj).intValue() == 0) { return StatusType.COMPARE_OK; } else if (!clsName.equals("java.sql.Date") || (!(oldObj instanceof String) && ((Number) oldObj).intValue() != 0)) { String msg = "New Value was null and shouldn't have been for Key Value New Field [" + newColName + "] [" + oldObj + "]"; log.error(msg); tblWriter.logErrors(newColName, msg); return StatusType.NEW_VAL_NULL; } } else { return StatusType.COMPARE_OK; } } StringBuilder errSB = new StringBuilder(); //System.out.println(newObj.getClass().getName()+" "+oldObj.getClass().getName()); if (newObj instanceof java.sql.Date) { boolean isPartialDate = false; Byte partialDateType = null; if (StringUtils.contains(newRsmd.getColumnName(newColInx + 1), "DatePrecision")) { partialDateType = newDBRS.getByte(newColInx); isPartialDate = true; } if (compareTo6DBs) { Object dateObj = oldDBRS.getObject(oldColInx); boolean isPartialDate2 = false; Byte partialDateType2 = null; if (StringUtils.contains(oldRsmd.getColumnName(oldColInx + 1), "DatePrecision")) { partialDateType2 = newDBRS.getByte(oldColInx); isPartialDate2 = true; } else { log.error("Next isn't DatePrecision and can't be!"); tblWriter.logErrors(oldNewIdStr, errSB.toString()); } if (!newObj.equals(dateObj) || (isPartialDate2 && !partialDateType2.equals(partialDateType))) { errSB.insert(0, oldColName + " "); errSB.append("["); errSB.append(datePair); errSB.append("]["); errSB.append(dateFormatter.format((Date) newObj)); errSB.append("] oldDate["); errSB.append(dateFormatter.format((Date) dateObj)); errSB.append("]"); log.error(errSB.toString()); tblWriter.logErrors(oldNewIdStr, errSB.toString()); return StatusType.BAD_DATE; } } else { int oldIntDate = oldDBRS.getInt(oldColInx); if (oldIntDate == 0) { return StatusType.NO_OLD_REC; } BasicSQLUtils.getPartialDate(oldIntDate, datePair, false); if (partialDateType != null) { if (Byte.parseByte(datePair.getPartial()) != partialDateType.byteValue()) { errSB.append("Partial Dates Type do not match. Old[" + datePair.getPartial() + "] New [" + partialDateType.byteValue() + "]"); // error partial dates don't match } } Calendar cal = Calendar.getInstance(); cal.setTime((Date) newObj); int year = Integer.parseInt(datePair.getDateStr().substring(0, 4)); int mon = Integer.parseInt(datePair.getDateStr().substring(5, 7)); int day = Integer.parseInt(datePair.getDateStr().substring(8, 10)); if (mon > 0) mon--; boolean isYearOK = true; int yr = cal.get(Calendar.YEAR); if (year != yr) { errSB.append("Year mismatch Old[" + year + "] New [" + yr + "] "); isYearOK = false; } if (mon != cal.get(Calendar.MONTH)) { errSB.append("Month mismatch Old[" + mon + "] New [" + cal.get(Calendar.MONTH) + "] "); } if (day != cal.get(Calendar.DAY_OF_MONTH)) { errSB.append("Day mismatch Old[" + day + "] New [" + cal.get(Calendar.DAY_OF_MONTH) + "] "); } if (errSB.length() > 0 && (!isYearOK || !isPartialDate)) { errSB.insert(0, oldColName + " "); errSB.append("["); errSB.append(datePair); errSB.append("]["); errSB.append(dateFormatter.format((Date) newObj)); errSB.append("]"); log.error(errSB.toString()); tblWriter.logErrors(oldNewIdStr, errSB.toString()); return StatusType.BAD_DATE; } } } return StatusType.COMPARE_OK; }
From source file:de.juwimm.cms.remote.ViewServiceSpringImpl.java
/** * Used for import single view component * @param parentId/*from w ww.j a va 2 s .c om*/ * @param doc * @param withChildren * @param picIds * @param docIds * @return */ private ViewComponentHbm createViewComponentFromXml(Integer parentId, Document doc, boolean withChildren, Hashtable<Integer, Integer> picIds, Hashtable<Integer, Integer> docIds, boolean useNewIds, Integer siteId, Integer fulldeploy, Integer newUnitId) { ViewComponentHbm viewComponent = ViewComponentHbm.Factory.newInstance(); ViewComponentHbm parent = getViewComponentHbmDao().load(parentId); try { Integer id = sequenceHbmDao.getNextSequenceNumber("viewcomponent.view_component_id"); viewComponent.setViewComponentId(id); } catch (Exception e) { log.error("Error creating/setting primary key", e); } Iterator it = XercesHelper.findNodes(doc, "//viewcomponent"); try { while (it.hasNext()) { Node nodeViewComponent = (Node) it.next(); Integer vcId = new Integer(((Element) nodeViewComponent).getAttribute("id")); Node nodeRealm = XercesHelper.findNode(nodeViewComponent, "realm2viewComponent"); /**import realms*/ importRealms(nodeViewComponent, siteId, useNewIds); importViewComponentPictures(nodeViewComponent, viewComponent); importViewComponentDocuments(nodeViewComponent, viewComponent); String linkName = XercesHelper.getNodeValue(nodeViewComponent, "//linkName"); String approvedLinkName = XercesHelper.getNodeValue(nodeViewComponent, "//approvedLinkName"); String statusInfo = XercesHelper.getNodeValue(nodeViewComponent, "//statusInfo"); String urlLinkName = XercesHelper.getNodeValue(nodeViewComponent, "//urlLinkName"); viewComponent.setDisplayLinkName(linkName); viewComponent.setApprovedLinkName(approvedLinkName); viewComponent.setLinkDescription(statusInfo); viewComponent.setUrlLinkName(urlLinkName); byte viewType = new Byte(XercesHelper.getNodeValue(nodeViewComponent, "//viewType")).byteValue(); boolean visible = Boolean.valueOf(XercesHelper.getNodeValue(nodeViewComponent, "//visible")) .booleanValue(); viewComponent.setMetaData(XercesHelper.getNodeValue(nodeViewComponent, "./metaKeywords")); viewComponent.setMetaDescription(XercesHelper.getNodeValue(nodeViewComponent, "./metaDescription")); String onlineStart = XercesHelper.getNodeValue(nodeViewComponent, "./onlineStart"); if (!onlineStart.equals("")) { if (log.isDebugEnabled()) log.debug("OnlineStart: " + onlineStart); viewComponent.setOnlineStart(Long.parseLong(onlineStart)); } String onlineStop = XercesHelper.getNodeValue(nodeViewComponent, "./onlineStop"); if (!onlineStop.equals("")) { if (log.isDebugEnabled()) log.debug("OnlineStop: " + onlineStop); viewComponent.setOnlineStop(Long.parseLong(onlineStop)); } viewComponent.setViewLevel(XercesHelper.getNodeValue(nodeViewComponent, "./viewLevel")); viewComponent.setViewIndex(XercesHelper.getNodeValue(nodeViewComponent, "./viewIndex")); viewComponent.setDisplaySettings( Byte.parseByte(XercesHelper.getNodeValue(nodeViewComponent, "./displaySettings"))); viewComponent .setShowType(Byte.parseByte(XercesHelper.getNodeValue(nodeViewComponent, "./showType"))); viewComponent.setViewType(viewType); viewComponent.setVisible(visible); viewComponent.setSearchIndexed(Boolean .valueOf(XercesHelper.getNodeValue(nodeViewComponent, "./searchIndexed")).booleanValue()); viewComponent.setXmlSearchIndexed( Boolean.valueOf(XercesHelper.getNodeValue(nodeViewComponent, "./xmlSearchIndexed")) .booleanValue()); byte status = Constants.DEPLOY_STATUS_EDITED; viewComponent.setStatus(status); viewComponent.setOnline((byte) 0); Element cnde = (Element) XercesHelper.findNode(nodeViewComponent, "//content"); if (cnde != null) { ContentHbm content = getContentHbmDao().createFromXml(cnde, false, false, picIds, docIds, mappingPersons, newUnitId); viewComponent.setReference(content.getContentId().toString()); } if (fulldeploy > 0) { // use new ids String neededrole = XercesHelper.getNodeValue(nodeRealm, "roleNeeded"); String loginPage = XercesHelper.getNodeValue(nodeRealm, "loginPageId"); if (loginPage != null && !"".equalsIgnoreCase(loginPage)) { Integer loginPageId = null; try { loginPageId = Integer.valueOf(loginPage); } catch (Exception e) { } if (loginPageId != null) loginPagesRealm2vc.put(vcId, loginPageId); } Node relNode = XercesHelper.findNode(nodeRealm, "jdbcRealmId"); if (relNode != null) { Integer id = new Integer(XercesHelper.getNodeValue(relNode)); RealmJdbcHbm sqlrealm = super.getRealmJdbcHbmDao().load(mappingRealmsJdbc.get(id)); Realm2viewComponentHbm tempRealm = createTempRealm(viewComponent, neededrole, sqlrealm, null, null, null); Realm2viewComponentHbm r = super.getRealm2viewComponentHbmDao().create(tempRealm); viewComponent.setRealm2vc(r); } else { relNode = XercesHelper.findNode(nodeRealm, "simplePwRealmId"); if (relNode != null) { Integer id = new Integer(XercesHelper.getNodeValue(relNode)); RealmSimplePwHbm realm = super.getRealmSimplePwHbmDao() .load(mappingRealmsSimplePw.get(id)); Realm2viewComponentHbm tempRealm = createTempRealm(viewComponent, neededrole, null, realm, null, null); Realm2viewComponentHbm r = super.getRealm2viewComponentHbmDao().create(tempRealm); viewComponent.setRealm2vc(r); } else { relNode = XercesHelper.findNode(nodeRealm, "ldapRealmId"); if (relNode != null) { Integer id = new Integer(XercesHelper.getNodeValue(relNode)); RealmLdapHbm realm = super.getRealmLdapHbmDao().load(mappingRealmsLdap.get(id)); Realm2viewComponentHbm tempRealm = createTempRealm(viewComponent, neededrole, null, null, realm, null); Realm2viewComponentHbm r = super.getRealm2viewComponentHbmDao().create(tempRealm); viewComponent.setRealm2vc(r); } else { relNode = XercesHelper.findNode(nodeRealm, "jaasRealmId"); if (relNode != null) { Integer id = new Integer(XercesHelper.getNodeValue(relNode)); RealmJaasHbm realm = super.getRealmJaasHbmDao().load(mappingRealmsJaas.get(id)); Realm2viewComponentHbm tempRealm = createTempRealm(viewComponent, neededrole, null, null, null, realm); Realm2viewComponentHbm r = super.getRealm2viewComponentHbmDao() .create(tempRealm); viewComponent.setRealm2vc(r); } } } } } else { Realm2viewComponentHbm tempRealm = new Realm2viewComponentHbmImpl(); tempRealm.setViewComponent(viewComponent); Realm2viewComponentHbm r = super.getRealm2viewComponentHbmDao().create(tempRealm); viewComponent.setRealm2vc(r); String loginPage = XercesHelper.getNodeValue(nodeRealm, "loginPageId"); if (loginPage != null && !"".equalsIgnoreCase(loginPage)) { Integer loginPageId = null; try { loginPageId = Integer.valueOf(loginPage); } catch (Exception e) { } } } } } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Error ar import viewcomponent"); } viewComponent.setChildren(null); viewComponent.setViewDocument(parent.getViewDocument()); return getViewComponentHbmDao().create(viewComponent); }
From source file:Arrays.java
/** * General copy-conversion method that copies N String elements * from an array of Strings into array of bytes. * * @param patDestination destination array of bytes * @param piDestinationFrom index in the destination to start place elements at * @param pastrSource source array of Strings * @param piSourceFrom index in the source to start take elements from * @param piHowMany N; how many elements to copy * * @throws NumberFormatException if one of the Strings doesn't have a properly formatted number * @since 0.3.0.3//from w w w . j av a 2 s .c om */ public static void copy(byte[] patDestination, int piDestinationFrom, String[] pastrSource, int piSourceFrom, int piHowMany) { for (int i = 0; i < piHowMany; i++) patDestination[piDestinationFrom + i] = Byte.parseByte(pastrSource[piSourceFrom + i]); }
From source file:de.juwimm.cms.remote.EditionServiceSpringImpl.java
/** * @param fulldeploy/* www .ja v a 2 s . co m*/ * means, if this is an import of an Full-Edition, Unit-Edition or Live-Deploy * <ul> * <li>0 - means LiveDeploy</li> * <li>1 - means Fulldeploy of an FullEdition</li> * <li>2 - means Fulldeploy of an UnitEdition</li> * </ul> */ private ViewComponentHbm createViewComponent(Integer unitId, ViewDocumentHbm viewDocument, ArrayList<ViewComponentHbm> savedUnits, Element nde, ViewComponentHbm parent, ViewComponentHbm prev, boolean livedeploy, int fulldeploy, boolean useNewIds) throws Exception { boolean reusePrimaryKey = (fulldeploy == 0); ViewComponentHbm viewComponent = null; try { Integer myUnitId = new Integer(nde.getAttribute("unitId")); Integer vcId = new Integer(nde.getAttribute("id")); if (fulldeploy == 2 && !myUnitId.equals(unitId)) { return null; } else if (fulldeploy > 0 || myUnitId.equals(unitId)) { String reference = XercesHelper.getNodeValue(nde, "./reference"); String linkName = XercesHelper.getNodeValue(nde, "./linkName"); String approvedLinkName = XercesHelper.getNodeValue(nde, "./approvedLinkName"); String statusInfo = XercesHelper.getNodeValue(nde, "./statusInfo"); String urlLinkName = XercesHelper.getNodeValue(nde, "./urlLinkName"); byte viewType = new Byte(XercesHelper.getNodeValue(nde, "./viewType")).byteValue(); boolean visible = Boolean.valueOf(XercesHelper.getNodeValue(nde, "./visible")).booleanValue(); if (livedeploy && (viewType == Constants.VIEW_TYPE_CONTENT || viewType == Constants.VIEW_TYPE_UNIT)) { Node publsh = XercesHelper.findNode(nde, "./content/contentVersion/version[string()='PUBLS']"); if (log.isDebugEnabled()) log.debug("viewType " + viewType); if (publsh == null) { if (log.isDebugEnabled()) log.debug("Haven't found a Cool-Online-Version (PUBLS), does not create VC " + vcId); return null; } } if (fulldeploy > 0) { if (useNewIds) { viewComponent = getViewComponentHbmDao().create(viewDocument, reference, linkName, statusInfo, urlLinkName, null); viewComponent.setApprovedLinkName(approvedLinkName); mappingVCs.put(vcId, viewComponent.getViewComponentId()); } else { // viewDocs can only be crated with viewComps if (viewDocument.getViewComponent().getViewComponentId().compareTo(vcId) == 0) { viewComponent = viewDocument.getViewComponent(); } else { viewComponent = getViewComponentHbmDao().load(vcId); } if (viewComponent == null) { viewComponent = getViewComponentHbmDao().create(viewDocument, reference, linkName, statusInfo, urlLinkName, vcId); } else { viewComponent.setDisplayLinkName(linkName); viewComponent.setViewDocument(viewDocument); viewComponent.setReference(reference); viewComponent.setUrlLinkName(urlLinkName); viewComponent.setLinkDescription(statusInfo); } viewComponent.setApprovedLinkName(approvedLinkName); mappingVCs.put(vcId, vcId); } if (fulldeploy == 1) { Integer newUnitId = mappingUnits.get(myUnitId); if (newUnitId == null) { newUnitId = myUnitId; } if (unitId == null || !newUnitId.equals(unitId)) { if (log.isDebugEnabled()) log.debug("newUnitId " + newUnitId + " myUnitId " + myUnitId); UnitHbm unit = getUnitHbmDao().load(newUnitId); viewComponent.setAssignedUnit(unit); unitId = unit.getUnitId(); } } } else { try { if (log.isDebugEnabled()) log.debug("searching ViewComponent: " + vcId); viewComponent = getViewComponentHbmDao().load(vcId); viewComponent.setViewDocument(viewDocument); viewComponent.setReference(reference); viewComponent.setDisplayLinkName(linkName); viewComponent.setLinkDescription(statusInfo); viewComponent.setUrlLinkName(urlLinkName); viewComponent.setApprovedLinkName(approvedLinkName); } catch (Exception e) { if (log.isDebugEnabled()) log.debug("error, creating ViewComponent: " + vcId); ViewComponentHbm tempVC = new ViewComponentHbmImpl(); tempVC.setViewDocument(viewDocument); tempVC.setReference(reference); tempVC.setLinkDescription(linkName); tempVC.setStatus(Integer.parseInt(statusInfo)); tempVC.setUrlLinkName(urlLinkName); tempVC.setViewComponentId(vcId); viewComponent = getViewComponentHbmDao().create(tempVC); viewComponent.setApprovedLinkName(approvedLinkName); } viewComponent.setOnline((byte) 1); } viewComponent.setPrevNode(prev); if (prev != null) prev.setNextNode(viewComponent); viewComponent.setParentViewComponent(parent); viewComponent.setMetaData(XercesHelper.getNodeValue(nde, "./metaKeywords")); viewComponent.setMetaDescription(XercesHelper.getNodeValue(nde, "./metaDescription")); String onlineStart = XercesHelper.getNodeValue(nde, "./onlineStart"); if (!onlineStart.equals("")) { if (log.isDebugEnabled()) log.debug("OnlineStart: " + onlineStart); viewComponent.setOnlineStart(Long.parseLong(onlineStart)); } String onlineStop = XercesHelper.getNodeValue(nde, "./onlineStop"); if (!onlineStop.equals("")) { if (log.isDebugEnabled()) log.debug("OnlineStop: " + onlineStop); viewComponent.setOnlineStop(Long.parseLong(onlineStop)); } viewComponent.setViewLevel(XercesHelper.getNodeValue(nde, "./viewLevel")); viewComponent.setViewIndex(XercesHelper.getNodeValue(nde, "./viewIndex")); viewComponent .setDisplaySettings(Byte.parseByte(XercesHelper.getNodeValue(nde, "./displaySettings"))); viewComponent.setShowType(Byte.parseByte(XercesHelper.getNodeValue(nde, "./showType"))); viewComponent.setViewType(viewType); viewComponent.setVisible(visible); viewComponent.setSearchIndexed( Boolean.valueOf(XercesHelper.getNodeValue(nde, "./searchIndexed")).booleanValue()); viewComponent.setXmlSearchIndexed( Boolean.valueOf(XercesHelper.getNodeValue(nde, "./xmlSearchIndexed")).booleanValue()); byte status = -1; try { status = new Byte(XercesHelper.getNodeValue(nde, "./status")).byteValue(); } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Status was not set..."); } // on import set deploy-state to "edited" if (!livedeploy) status = Constants.DEPLOY_STATUS_EDITED; viewComponent.setStatus(status); byte onlineState = -1; try { onlineState = new Byte(XercesHelper.getNodeValue(nde, "./online")).byteValue(); } catch (Exception e) { if (log.isDebugEnabled()) log.debug("OnlineState was not set..."); } // on import set online-state to offline if (!livedeploy) onlineState = Constants.ONLINE_STATUS_OFFLINE; viewComponent.setOnline(onlineState); if (fulldeploy == 0 && viewComponent.getStatus() == Constants.DEPLOY_STATUS_APPROVED) { // this only occures on new pages that are deployed for the first time // (they dont have the state online on workserver because of different transactions) if (log.isDebugEnabled()) log.debug("setting online: " + viewComponent.getDisplayLinkName()); viewComponent.setOnline((byte) 1); } { // realm2viewComponent Node nodeRealm = XercesHelper.findNode(nde, "realm2viewComponent"); if (nodeRealm != null) { // this ViewComponent is protected by a realm if (fulldeploy > 0) { // use new ids String neededrole = XercesHelper.getNodeValue(nodeRealm, "roleNeeded"); String loginPage = XercesHelper.getNodeValue(nodeRealm, "loginPageId"); if (loginPage != null && !"".equalsIgnoreCase(loginPage)) { Integer loginPageId = null; try { loginPageId = Integer.valueOf(loginPage); } catch (Exception e) { } if (loginPageId != null) loginPagesRealm2vc.put(vcId, loginPageId); } Node relNode = XercesHelper.findNode(nodeRealm, "jdbcRealmId"); if (relNode != null) { Integer id = new Integer(XercesHelper.getNodeValue(relNode)); RealmJdbcHbm sqlrealm = null; if (useNewIds) { sqlrealm = getRealmJdbcHbmDao().load(mappingRealmsJdbc.get(id)); } else { sqlrealm = getRealmJdbcHbmDao().load(id); } Realm2viewComponentHbm tempRealm = createTempRealm(viewComponent, neededrole, sqlrealm, null, null, null); Realm2viewComponentHbm r = getRealm2viewComponentHbmDao().create(tempRealm); viewComponent.setRealm2vc(r); } else { relNode = XercesHelper.findNode(nodeRealm, "simplePwRealmId"); if (relNode != null) { Integer id = new Integer(XercesHelper.getNodeValue(relNode)); RealmSimplePwHbm realm = null; if (useNewIds) { realm = getRealmSimplePwHbmDao().load(mappingRealmsSimplePw.get(id)); } else { realm = getRealmSimplePwHbmDao().load(id); } Realm2viewComponentHbm tempRealm = createTempRealm(viewComponent, neededrole, null, realm, null, null); Realm2viewComponentHbm r = getRealm2viewComponentHbmDao().create(tempRealm); viewComponent.setRealm2vc(r); } else { relNode = XercesHelper.findNode(nodeRealm, "ldapRealmId"); if (relNode != null) { Integer id = new Integer(XercesHelper.getNodeValue(relNode)); RealmLdapHbm realm = null; if (useNewIds) { realm = getRealmLdapHbmDao().load(mappingRealmsLdap.get(id)); } else { realm = getRealmLdapHbmDao().load(id); } Realm2viewComponentHbm tempRealm = createTempRealm(viewComponent, neededrole, null, null, realm, null); Realm2viewComponentHbm r = getRealm2viewComponentHbmDao().create(tempRealm); viewComponent.setRealm2vc(r); } else { relNode = XercesHelper.findNode(nodeRealm, "jaasRealmId"); if (relNode != null) { Integer id = new Integer(XercesHelper.getNodeValue(relNode)); RealmJaasHbm realm = null; if (useNewIds) { realm = getRealmJaasHbmDao().load(mappingRealmsJaas.get(id)); } else { realm = getRealmJaasHbmDao().load(id); } Realm2viewComponentHbm tempRealm = createTempRealm(viewComponent, neededrole, null, null, null, realm); Realm2viewComponentHbm r = getRealm2viewComponentHbmDao() .create(tempRealm); viewComponent.setRealm2vc(r); } } } } } else { Realm2viewComponentHbm tempRealm = new Realm2viewComponentHbmImpl(); tempRealm.setViewComponent(viewComponent); Realm2viewComponentHbm r = getRealm2viewComponentHbmDao().create(tempRealm); viewComponent.setRealm2vc(r); String loginPage = XercesHelper.getNodeValue(nodeRealm, "loginPageId"); if (loginPage != null && !"".equalsIgnoreCase(loginPage)) { Integer loginPageId = null; try { loginPageId = Integer.valueOf(loginPage); } catch (Exception e) { } if (loginPageId != null) loginPagesRealm2vc.put(vcId, loginPageId); } } } } // CONTENT Element cnde = (Element) XercesHelper.findNode(nde, "./content"); if (cnde != null) { ContentHbm content = getContentHbmDao().createFromXml(cnde, reusePrimaryKey, livedeploy, null, null, null, null); viewComponent.setReference(content.getContentId().toString()); } // CHILDREN Iterator it = XercesHelper.findNodes(nde, "./viewcomponent"); ViewComponentHbm childprev = null; ViewComponentHbm tmp = null; while (it.hasNext()) { Element childnode = (Element) it.next(); tmp = createViewComponent(unitId, viewDocument, savedUnits, childnode, viewComponent, childprev, livedeploy, fulldeploy, useNewIds); if (childprev != null) { childprev.setNextNode(tmp); } else { viewComponent.setFirstChild(tmp); } if (tmp != null) childprev = tmp; } } else { // Im a ViewComponent from another Unit. This must be inside the Array... HEY ARRAY !!! boolean found = false; Iterator it = savedUnits.iterator(); while (it.hasNext()) { ViewComponentHbm savedvc = (ViewComponentHbm) it.next(); if (myUnitId.equals(savedvc.getAssignedUnit().getUnitId())) { viewComponent = savedvc; viewComponent.setPrevNode(prev); byte showtype = viewComponent.getShowType(); viewComponent.setParentViewComponent(parent); viewComponent.setShowType(showtype); savedUnits.remove(savedvc); found = true; if (log.isDebugEnabled()) log.debug("MOVING BACK: " + viewComponent.getDisplayLinkName()); break; } } if (!found) { // This means: We are importing a Edition, where we suggest, that there is already this // Unit deployed, what we have as child-Unit. // It is possible, that we are deploying a unit, where this child-Unis haven't deployed yet - // f.e. initial-deploy or this child-unit has been new created and never deployed at this special // moment. // Therefor we will create a DUMMY entry with a "DUMMY"-Reference, so we can map the child-unit to // this place, if the child-Unit Editor wants to deploy his unit. try { // FIRST we will take a look, if there is already this Unit - but wasn't found here. // This could be possible, if this unit was been "outtaked" and this is an old Edition, // we will find this Unit anywhere else. viewComponent = getViewComponentHbmDao().find4Unit(myUnitId, viewDocument.getViewDocumentId()); } catch (Exception exe) { try { UnitHbm unit = getUnitHbmDao().load(myUnitId); ViewComponentHbm tempVC = new ViewComponentHbmImpl(); tempVC.setViewDocument(viewDocument); tempVC.setReference("DUMMY"); tempVC.setDisplayLinkName("SUB_ENTRY_NOT_DEPLOYED"); tempVC.setLinkDescription("SUB_ENTRY_NOT_DEPLOYED"); tempVC.setViewComponentId(vcId); viewComponent = getViewComponentHbmDao().create(tempVC); viewComponent.setViewType(Constants.VIEW_TYPE_UNIT); viewComponent.setVisible(false); viewComponent.setAssignedUnit(unit); } catch (Exception ex) { // Jens - ?? // context.setRollbackOnly(); throw new UserException("UnitWasNeverDeployed"); } } viewComponent.setPrevNode(prev); viewComponent.setParentViewComponent(parent); } } } catch (Exception exe) { // Jens - ?? // context.setRollbackOnly(); log.error("Error occured", exe); throw exe; } // IMPORT END return viewComponent; }
From source file:org.openTwoFactor.client.util.TwoFactorClientCommonUtils.java
/** * convert an object to a byte// w w w.j a va2 s.com * @param input * @return the byte */ public static byte byteValue(Object input) { if (input instanceof String) { String string = (String) input; return Byte.parseByte(string); } if (input instanceof Number) { return ((Number) input).byteValue(); } throw new RuntimeException("Cannot convert to byte: " + className(input)); }
From source file:ca.oson.json.Oson.java
private <E> Byte json2Byte(FieldData objectDTO) { if (objectDTO == null || !objectDTO.json2Java) { return null; }//from w ww. ja va2 s . c o m Object value = objectDTO.valueToProcess; Class<E> returnType = objectDTO.returnType; if (value != null && value.toString().trim().length() > 0) { String valueToProcess = value.toString().trim(); Byte valueToReturn = null; try { Function function = objectDTO.getDeserializer(); if (function != null) { try { Object returnedValue = null; if (function instanceof Json2DataMapperFunction) { DataMapper classData = new DataMapper(returnType, value, objectDTO.classMapper, objectDTO.level, getPrettyIndentation()); returnedValue = ((Json2DataMapperFunction) function).apply(classData); } else if (function instanceof Json2FieldDataFunction) { Json2FieldDataFunction f = (Json2FieldDataFunction) function; FieldData fieldData = objectDTO.clone(); returnedValue = f.apply(fieldData); } else if (function instanceof Json2ByteFunction) { return ((Json2ByteFunction) function).apply(valueToProcess); } else { returnedValue = function.apply(valueToProcess); } if (returnedValue instanceof Optional) { returnedValue = ObjectUtil.unwrap(returnedValue); } if (returnedValue == null) { return null; } else if (Number.class.isAssignableFrom(returnedValue.getClass()) || returnedValue.getClass().isPrimitive()) { if (returnedValue instanceof Byte) { valueToReturn = (Byte) returnedValue; } else if (returnedValue instanceof String) { valueToReturn = Byte .parseByte(NumberUtil.removeTrailingDecimalZeros(returnedValue)); } else if (returnedValue instanceof Integer) { valueToReturn = ((Integer) returnedValue).byteValue(); } else if (returnedValue instanceof Long) { valueToReturn = ((Long) returnedValue).byteValue(); } else if (returnedValue instanceof Short) { valueToReturn = ((Short) returnedValue).byteValue(); } else if (returnedValue instanceof Double) { valueToReturn = ((Double) returnedValue).byteValue(); } else if (returnedValue instanceof Float) { valueToReturn = ((Float) returnedValue).byteValue(); } else if (returnedValue instanceof BigInteger) { valueToReturn = ((BigInteger) returnedValue).byteValue(); } else if (returnedValue instanceof BigDecimal) { valueToReturn = ((BigDecimal) returnedValue).byteValue(); } else if (returnedValue instanceof AtomicInteger) { valueToReturn = ((AtomicInteger) returnedValue).byteValue(); } else if (returnedValue instanceof AtomicLong) { valueToReturn = ((AtomicLong) returnedValue).byteValue(); } else { valueToReturn = ((Number) returnedValue).byteValue(); } } else if (returnedValue instanceof Character) { char c = (Character) returnedValue; valueToReturn = (byte) c; } else if (returnedValue instanceof Boolean) { if ((Boolean) returnedValue) valueToReturn = 1; else valueToReturn = 0; } else if (Enum.class.isAssignableFrom(returnedValue.getClass())) { valueToReturn = ((Integer) ((Enum) returnedValue).ordinal()).byteValue(); } else if (Date.class.isAssignableFrom(returnedValue.getClass())) { valueToReturn = (byte) ((Date) returnedValue).getTime(); } else { valueToReturn = Byte.parseByte(NumberUtil.removeTrailingDecimalZeros(returnedValue)); } return valueToReturn; } catch (Exception e) { e.printStackTrace(); } } else { long longValue = Long.parseLong(NumberUtil.removeTrailingDecimalZeros(valueToProcess)); if (longValue > Byte.MAX_VALUE) { valueToReturn = Byte.MAX_VALUE; } else { valueToReturn = (byte) longValue; } // valueToReturn = Byte.parseByte(valueToProcess); } if (valueToReturn != null) { Long min = objectDTO.getMin(); Long max = objectDTO.getMax(); if (min != null && min.byteValue() > valueToReturn) { return min.byteValue(); } if (max != null && max.byteValue() < valueToReturn) { valueToReturn = max.byteValue(); } return valueToReturn; } } catch (Exception ex) { //ex.printStackTrace(); } } return json2ByteDefault(objectDTO); }
From source file:com.clark.func.Functions.java
/** * <p>//www. jav a2s . c o m * Convert a <code>String</code> to a <code>byte</code>, returning a default * value if the conversion fails. * </p> * * <p> * If the string is <code>null</code>, the default value is returned. * </p> * * <pre> * NumberUtils.toByte(null, 1) = 1 * NumberUtils.toByte("", 1) = 1 * NumberUtils.toByte("1", 0) = 1 * </pre> * * @param str * the string to convert, may be null * @param defaultValue * the default value * @return the byte represented by the string, or the default if conversion * fails * @since 2.5 */ public static byte toByte(String str, byte defaultValue) { if (str == null) { return defaultValue; } try { return Byte.parseByte(str); } catch (NumberFormatException nfe) { return defaultValue; } }