List of usage examples for org.dom4j Element elementText
String elementText(QName qname);
From source file:com.noterik.bart.fs.action.PresentationIndexAction.java
License:Open Source License
/** * Create XML for an index/*from w ww . jav a2s . co m*/ * * @param typeContent * @param presentationUri * @param presentationDetails * @param collectionDetails * @param iConfig */ private static void makeType(Element typeContent, String presentationUri, Map<String, Object> presentationDetails, Map<String, Object> collectionDetails, IndexConfig iConfig) { // create new type Document typeDocument = DocumentHelper.createDocument(); Element fsxml = typeDocument.addElement("fsxml"); Element type = fsxml.addElement(iConfig.getIndexType()); // add refer to original presentation Element referPresentation = type.addElement("presentation"); referPresentation.addAttribute("id", "1"); referPresentation.addAttribute("referid", presentationUri); // add refer to original collection Element referCollectionPresentation = type.addElement("collectionpresentation"); referCollectionPresentation.addAttribute("id", "1"); String collectionPresentation = (String) collectionDetails.get("presentation"); collectionPresentation = collectionPresentation.substring(0, collectionPresentation.length() - 1); referCollectionPresentation.addAttribute("referid", (String) collectionPresentation); Element properties = type.addElement("properties"); //add standard properties properties.addElement("presentation").addText((String) collectionDetails.get("presentation")); properties.addElement("presentationuri").addText(presentationUri + "/"); properties.addElement("collection").addText((String) collectionDetails.get("collection")); properties.addElement("presentationtitle").addText((String) presentationDetails.get("presentationtitle")); properties.addElement("presentationdescription") .addText((String) presentationDetails.get("presentationdescription")); properties.addElement("presentationscreenshot") .addText((String) presentationDetails.get("presentationscreenshot")); properties.addElement("presentationtype").addText((String) presentationDetails.get("presentationtype")); properties.addElement("presentationauthor").addText((String) presentationDetails.get("presentationauthor")); properties.addElement("presentationcopyright") .addText((String) presentationDetails.get("presentationcopyright")); properties.addElement("presentationwebsite") .addText((String) presentationDetails.get("presentationwebsite")); //add user configured properties Map<String, String> items = iConfig.getProperties(); Element typeProperties = typeContent.element("properties"); double start = typeProperties.elementText("starttime") == null ? 0.0 : Double.parseDouble(typeProperties.elementText("starttime")); double duration = typeProperties.elementText("duration") == null ? 0.0 : Double.parseDouble(typeProperties.elementText("duration")); if (duration == 0.0) { duration = typeProperties.elementText("length") == null ? 0.0 : Double.parseDouble(typeProperties.elementText("length")); } for (String item : items.keySet()) { if (item.equals("collectiontitle") || item.equals("collectiondescription") || item.equals("collectionstatus")) { properties.addElement(item).addText((String) collectionDetails.get(item)); } else if (item.equals("lockmode") || item.equals("link") || item.equals("date_created") || item.equals("presentationduration") || item.equals("presentationtheme") || item.equals("presentationlocation") || item.equals("presentationdate") || item.equals("presentationdate_original") || item.equals("presentationpublic") || item.equals("sponsor")) { properties.addElement(item).addText((String) presentationDetails.get(item)); } else if (item.equals("title") || item.equals("description") || item.equals("name")) { String value = typeProperties.elementText(item) == null ? "" : typeProperties.elementText(item); properties.addElement(item).addText(value); } else if (item.equals("firstnamelastname")) { String firstname = typeProperties.elementText("firstname") == null ? "" : typeProperties.elementText("firstname"); String lastname = typeProperties.elementText("lastname") == null ? "" : typeProperties.elementText("lastname"); properties.addElement("name").addText(firstname + " " + lastname); } else if (item.equals("screenshot")) { //former chapterscreenshot properties.addElement(item) .addText(getTypeScreenshot((Document) presentationDetails.get("presentation"), start, (String) presentationDetails.get("presentationscreenshot"))); } else if (item.equals("rank")) { properties.addElement(item).addText( String.valueOf(getRankBasedOnLockmode((String) presentationDetails.get("lockmode")))); } else if (item.equals("start")) { properties.addElement(item).addText(String.format(Locale.US, "%f", start)); } else if (item.equals("duration")) { properties.addElement(item).addText(String.format(Locale.US, "%f", duration)); } else if (item.equals("locations")) { properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"), "location", start, duration, new String[] { "name" })); } else if (item.equals("dates")) { properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"), "date", start, duration, new String[] { "start", "end" })); } else if (item.equals("keywords")) { properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"), "keyword", start, duration, new String[] { "name" })); } else if (item.equals("persons")) { properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"), "person", start, duration, new String[] { "name" })); } else if (item.equals("periods")) { properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"), "period", start, duration, new String[] { "name" })); } else if (item.equals("speakers")) { properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"), "speakers", start, duration, new String[] { "firstname", "lastname", "organization" })); } else if (item.equals("topics")) { properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"), "topics", start, duration, new String[] { "name" })); } else if (item.equals("peercomments")) { properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"), "peercomments", 0.0, 86400000.0, new String[] { "comment" })); } else if (item.equals("voiceindex")) { String voiceindex = typeProperties.elementText("voiceindex") == null ? "" : typeProperties.elementText("voiceindex"); properties.addElement(item).addText(voiceindex); } else if (item.equals("presentation" + iConfig.getIndexType())) { properties.addElement(item).addText(getTypeUri(typeContent, presentationUri, iConfig)); } else if (item.equals("bookmark")) { properties.addElement(item).addText(getType((Document) presentationDetails.get("presentation"), "bookmark", 0.0, 86400000.0, new String[] { "title", "description", "creator" })); } else if (item.equals("webtv_item_id") || item.equals("presentationlivestate")) { properties.addElement(item).addText((String) presentationDetails.get(item)); } } long timestamp = new Date().getTime(); type.addAttribute("id", String.valueOf(timestamp)); // Add directly to fs so maggie get's updated with first content faster FSXMLRequestHandler.instance().saveFsXml(iConfig.getIndexUri(), typeDocument.asXML(), "PUT", true); }
From source file:com.npower.dm.hibernate.management.ModelManagementBeanImpl.java
License:Open Source License
/** * //from w w w . j av a 2s .c o m * <pre> * Import the TAC list of models form file. * <pre> * * @param xmlFile * @throws DMException * */ public void importModelTAC(File xmlFile) throws DMException { try { ManagementBeanFactory factory = this.getManagementBeanFactory(); ModelBean modelBean = factory.createModelBean(); factory.beginTransaction(); SAXReader reader = new SAXReader(); Document confDoc = reader.read(xmlFile); Element root = confDoc.getRootElement(); for (Iterator<Element> i = root.elementIterator("Manufacturer"); i.hasNext();) { String manufacturerExternalID = ""; Element manElement = i.next(); manufacturerExternalID = manElement.elementText("ExternalID"); Manufacturer manufacturerBean = modelBean.getManufacturerByExternalID(manufacturerExternalID); if (manufacturerBean == null) { System.err.println("Could not find this manufacturer: " + manufacturerExternalID); continue; } for (Iterator<Element> j = manElement.elementIterator("Model"); j.hasNext();) { String modelExternalID = ""; Element modelElement = j.next(); modelExternalID = modelElement.elementText("ExternalID"); Model model = modelBean.getModelByManufacturerModelID(manufacturerBean, modelExternalID); if (model == null) { System.err.println("Could not find this model: " + modelExternalID); continue; } List<Element> TACsList = modelElement.elements("TACs"); List<String> TACInfos = new ArrayList<String>(); for (int k = 0; k < TACsList.size(); k++) { List<Element> TACList = ((TACsList.get(k))).elements("TAC"); for (int m = 0; m < TACList.size(); m++) { Element tacElement = TACList.get(m); String tac = tacElement.getText(); if (StringUtils.isNotEmpty(tac) && tac.length() >= 8) { TACInfos.add(tac); } } } modelBean.update(model); modelBean.setTACInfos(model, TACInfos); } } factory.commit(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.openedit.users.filesystem.FileSystemUserManager.java
License:Open Source License
/** * @see com.openedit.users.UserManager#getGroup(String) *///from w w w .j av a 2s . co m public Group getGroup(String inGroupId) { Group group = (Group) getGroupIdToGroupMap().get(inGroupId); File find = loadGroupFile(inGroupId); if (group != null) { if (group.getLastModified() == find.lastModified()) { return group; } } if (!find.exists()) { ContentItem stub = getPageManager().getRepository().getStub("/WEB-INF/groups/" + inGroupId + ".xml"); find = new File(stub.getAbsolutePath()); } if (!find.exists()) { return null; } if (group == null) { group = new FileSystemGroup(); } FileSystemGroup loadgroup = (FileSystemGroup) group; group = loadgroup; loadgroup.setLastModified(find.lastModified()); getGroupIdToGroupMap().put(inGroupId, group); Element root = getXmlUtil().getXml(find, "UTF-8"); loadgroup.setId(root.attributeValue("id")); if (loadgroup.getId() == null) { loadgroup.setId(inGroupId); } loadgroup.setName(root.elementText("group-name")); if (loadgroup.getName() == null) { loadgroup.setName(inGroupId); } Element perm = root.element("permissions"); if (perm != null) { for (Iterator iterator = perm.elementIterator("permission"); iterator.hasNext();) { Element type = (Element) iterator.next(); loadgroup.addPermission(type.getTextTrim()); } } MapPropertyContainer properties = new MapPropertyContainer(); Element props = root.element("properties"); properties.loadProperties(props); loadgroup.setPropertyContainer(properties); return loadgroup; }
From source file:com.openedit.users.filesystem.XmlUserArchive.java
License:Open Source License
/** * @see com.openedit.users.UserManager#getGroup(String) *//*from w ww.j a v a 2s. com*/ public Group getGroup(String inGroupId) { Group group = (Group) getGroupIdToGroupMap().get(inGroupId); File find = loadGroupFile(inGroupId); if (group != null) { if (group.getLastModified() == find.lastModified()) { return group; } } if (!find.exists()) { ContentItem stub = getPageManager().getRepository().getStub("/WEB-INF/groups/" + inGroupId + ".xml"); find = new File(stub.getAbsolutePath()); } if (!find.exists()) { return null; } if (group == null) { // System.out.println("calling " + inGroupId + " " + hashCode() ); group = new FileSystemGroup(); } FileSystemGroup loadgroup = (FileSystemGroup) group; group = loadgroup; loadgroup.setLastModified(find.lastModified()); getGroupIdToGroupMap().put(inGroupId, group); Element root = getXmlUtil().getXml(find, "UTF-8"); loadgroup.setId(root.attributeValue("id")); if (loadgroup.getId() == null) { loadgroup.setId(inGroupId); } loadgroup.setName(root.elementText("group-name")); if (loadgroup.getName() == null) { loadgroup.setName(inGroupId); } Element perm = root.element("permissions"); if (perm != null) { for (Iterator iterator = perm.elementIterator("permission"); iterator.hasNext();) { Element type = (Element) iterator.next(); loadgroup.addPermission(type.getTextTrim()); } } MapPropertyContainer properties = new MapPropertyContainer(); Element props = root.element("properties"); properties.loadProperties(props); loadgroup.setPropertyContainer(properties); return loadgroup; }
From source file:com.openkm.bean.openmeetings.Room.java
License:Open Source License
/** * Room//from w w w . j av a 2 s . c o m * * @throws ParseException */ public Room(Element element) throws ParseException { if (element.elementText("name") != null) { name = element.elementText("name"); } if (element.elementText("rooms_id") != null) { // Depending the xml result comes with room_id or rooms_id id = Integer.parseInt(element.elementText("rooms_id")); } else if (element.elementText("room_id") != null) { id = Integer.parseInt(element.elementText("room_id")); } if (element.element("roomtype") != null && element.element("roomtype").elementText("roomtypes_id") != null) { type = Integer.parseInt(element.element("roomtype").elementText("roomtypes_id")); } if (element.elementText("ispublic") != null) { pub = Boolean.getBoolean(element.elementText("ispublic")); } if (element.elementText("starttime") != null) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); start = sdf.parse(element.elementText("starttime")); } }
From source file:com.openkm.openmeetings.service.UserService.java
License:Open Source License
/** * loginUser/* w ww . j a v a2 s . c o m*/ * */ public static String loginUser() throws Exception { String SID = null; Map<String, Element> result = null; String sessionURL = OpenMeetingsUtils.getOpenMeetingServerURL() + "/services/UserService/getSession"; Map<String, Element> elementMap = RestService.callMap(sessionURL, null); Element item = (Element) elementMap.get("return"); SID = item.elementText("session_id"); log.info(SID); result = RestService.callMap( OpenMeetingsUtils.getOpenMeetingServerURL() + "/services/UserService/loginUser?SID=" + SID + "&username=" + Config.OPENMEETINGS_USER + "&userpass=" + Config.OPENMEETINGS_CREDENTIALS, null); if (Integer.valueOf(((Element) result.get("return")).getStringValue()).intValue() > 0) { return SID; } return null; }
From source file:com.oubeichen.gefexp.ShapesEditor.java
License:Open Source License
@Override protected void setInput(IEditorInput input) { super.setInput(input); try {//w w w .j ava 2 s. c om IFile file = ((IFileEditorInput) input).getFile(); if (!file.getName().contains(".raw.obsp")) {//XXX.raw.obsp ObjectInputStream in = new ObjectInputStream(file.getContents()); diagram = (ShapesDiagram) in.readObject(); in.close(); } else { diagram = new ShapesDiagram(); /*InputStreamReader isr = new InputStreamReader(file.getContents()); BufferedReader reader = new BufferedReader(isr); String tempString, name; ArrayList<String> shapename = new ArrayList<String>(); int shapenum, connnum; reader.readLine();//"Shape:" tempString = reader.readLine();//shape number try{ shapenum = Integer.parseInt(tempString); }catch(NumberFormatException ex){ shapenum = 0; } for(int i = 0;i < shapenum;i++){ int height, width, x, y; name = reader.readLine();//shape name shapename.add(name); reader.readLine();//"height:" tempString = reader.readLine();//shape height try{ height = Integer.parseInt(tempString); }catch(NumberFormatException ex){ height = 0; } reader.readLine();//"width:" tempString = reader.readLine();//shape width try{ width = Integer.parseInt(tempString); }catch(NumberFormatException ex){ width = 0; } reader.readLine();//"location:" tempString = reader.readLine();//shape location try{ x = Integer.parseInt(tempString.split(" ")[0]); }catch(NumberFormatException ex){ x = 0; } try{ y = Integer.parseInt(tempString.split(" ")[1]); }catch(NumberFormatException ex){ y = 0; } reader.readLine();//empty line //add to the diagram Shape sp; if(name.contains("Ellipse")){ sp = new EllipticalShape(); }else if(name.contains("Triangle")){ sp = new TriangularShape(); }else if(name.contains("Rectangle")){ sp = new RectangularShape(); }else{ System.err.println("Shape unsupported!"); sp = new EllipticalShape(); } sp.setSize(new Dimension(width, height)); sp.setLocation(new Point(x, y)); diagram.addChild(sp); } reader.readLine();//"Connections:" tempString = reader.readLine();//connection num try{ connnum = Integer.parseInt(tempString); }catch(NumberFormatException ex){ connnum = 0; } for(int i = 0;i < connnum;i++) { String source = reader.readLine(); String target = reader.readLine(); reader.readLine();//empty line int sourceindex = shapename.indexOf(source); int targetindex = shapename.indexOf(target); if(sourceindex == -1 || targetindex == -1) { System.err.println("Cannot find this shape!"); continue; } Shape sourceshape = (Shape) diagram.getChildren().get(sourceindex); Shape targetshape = (Shape) diagram.getChildren().get(targetindex); Connection conn = new Connection(sourceshape, targetshape); } reader.close();*/ SAXReader reader = new SAXReader(); Document document; try { reader.setEncoding("UTF-8"); document = reader.read(file.getContents());// } catch (DocumentException ex) { System.err.println("Cannot read input file!"); ex.printStackTrace(); throw new CoreException(null); } Element root = document.getRootElement(); Element shaperoot = root.element("shapes"); List list = shaperoot.elements("shape"); Iterator it = list.iterator(); ArrayList<String> shapename = new ArrayList<String>(); while (it.hasNext()) { Element shapeElm = (Element) it.next(); int height, width, x, y; String name = shapeElm.elementText("name"); try { height = Integer.parseInt(shapeElm.elementText("height")); width = Integer.parseInt(shapeElm.elementText("width")); x = Integer.parseInt(shapeElm.elementText("locx")); y = Integer.parseInt(shapeElm.elementText("locy")); Shape sp; if (name.contains("Ellipse")) { sp = new EllipticalShape(); } else if (name.contains("Triangle")) { sp = new TriangularShape(); } else if (name.contains("Rectangle")) { sp = new RectangularShape(); } else { System.err.println("Shape unsupported!"); sp = new EllipticalShape(); } diagram.addChild(sp); sp.setSize(new Dimension(width, height)); sp.setLocation(new Point(x, y)); shapename.add(name); } catch (Exception ex) { ex.printStackTrace(); } } Element connroot = root.element("connections"); list = connroot.elements("connection"); it = list.iterator(); while (it.hasNext()) { Element connElm = (Element) it.next(); String source = connElm.elementText("source"); String target = connElm.elementText("target"); int sourceindex = shapename.indexOf(source); int targetindex = shapename.indexOf(target); if (sourceindex == -1 || targetindex == -1) { System.err.println("Cannot find this shape!"); continue; } Shape sourceshape = (Shape) diagram.getChildren().get(sourceindex); Shape targetshape = (Shape) diagram.getChildren().get(targetindex); new Connection(sourceshape, targetshape); } } setPartName(file.getName()); } catch (CoreException e) { handleLoadException(e); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.pureinfo.srm.config.notice.model.NoticeItem.java
License:Open Source License
/** * @see com.pureinfo.force.xml.IXMLSupporter#fromXML(org.dom4j.Element) *//* w w w. j av a 2 s .c o m*/ public void fromXML(Element _element) throws PureException { m_sName = _element.attributeValue(ATTRIBUTE_NAME); m_bChecked = Boolean.valueOf(_element.elementText(ELEMENT_CHECKED)).booleanValue(); m_nDay = Integer.parseInt(_element.elementText(ELEMENT_DAY)); m_sText = _element.elementText(ELEMENT_TEXT); }
From source file:com.pureinfo.srm.srm2rpms.action.RPMSValidatorAction.java
License:Open Source License
/** * @see com.pureinfo.ark.interaction.ActionBase#beforeExecution() *///from w ww . j a v a 2s. com protected ActionForward beforeExecution() throws PureException { String sId = request.getRequiredParameter("id", "validator id"); String sFileName = ClassResourceUtil.mapFullPath("srm2rpms-validator.cfg.xml", true); Element element = XMLUtil.fileToElement(sFileName); List list = element.elements(); try { Iterator itrList = list.iterator(); while (itrList.hasNext()) { element = (Element) itrList.next(); if (sId.equals(element.attributeValue("id"))) { m_sTitle = element.attributeValue("title"); m_sScenery = element.attributeValue("scenery"); m_sHeadTable = element.elementText("hint"); String sCondition = element.elementTextTrim("condition"); ((SearchForm) form).getQueryFilter().addCondition(sCondition); return super.beforeExecution(); } } // endwhile } finally { list.clear(); } throw new PureException(PureException.INVALID_REQUEST, "validator not found: id=" + sId); }
From source file:com.rowtheboat.gui.OptionsSingleton.java
License:Open Source License
/** * A private constructor to ensure that only one instance is created. *//*from w ww . j ava 2s . c o m*/ private OptionsSingleton() { /* Retrieve the serial ports and set the first as standard */ Enumeration ports = CommPortIdentifier.getPortIdentifiers(); serialPort = ((CommPortIdentifier) ports.nextElement()).getName(); /* Find the current location and use this to create the optionsFile. This resolves issues * with jar files */ String currentDir = ""; try { currentDir = (new File(".")).getCanonicalPath() + File.separator; } catch (IOException e1) { /* Nothing we can do here. This means the optionsFile will just be the options file * name, which will still work in most cases but in jar files on linux */ e1.printStackTrace(); } optionsFile = new File(currentDir + OPTIONS_FILE_NAME); /* Read in existing options, if they exist */ SAXReader reader = new SAXReader(); try { Document document = reader.read(optionsFile); /* Get the root element */ Element root = document.getRootElement(); /* Update the standard options */ Element standardElement = root.element("Standard"); this.setFullStrokeData(Boolean.valueOf(standardElement.elementText("FullStrokeData")).booleanValue()); this.setBoatSmoothing(Boolean.valueOf(standardElement.elementText("BoatSmoothing")).booleanValue()); /* Update the input options */ Element inputElement = root.element("Input"); String portFromFile = inputElement.elementText("SerialPort"); /* Check the port is valid, if not then default is used */ Enumeration possiblePorts = CommPortIdentifier.getPortIdentifiers(); while (possiblePorts.hasMoreElements()) { if (((CommPortIdentifier) possiblePorts.nextElement()).getName().equals(portFromFile)) { setSerialPort(portFromFile); } } /* Update the race options */ Element raceElement = root.element("Race"); this.setDelay(Byte.parseByte(raceElement.elementText("Countdown"))); } catch (Exception e) { /* Do nothing as file not present - thus defaults will be used */ } }