List of usage examples for org.dom4j Element elementText
String elementText(QName qname);
From source file:com.liferay.portal.tools.EJBXMLBuilder.java
License:Open Source License
private void _buildSunXML() throws Exception { StringBuffer sb = new StringBuffer(); sb.append("<?xml version=\"1.0\"?>\n"); sb.append(/*from w ww . j a v a 2 s. c om*/ "<!DOCTYPE sun-ejb-jar PUBLIC \"-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 EJB 2.0//EN\" \"http://www.sun.com/software/sunone/appserver/dtds/sun-ejb-jar_2_0-0.dtd\">\n"); sb.append("\n<sun-ejb-jar>\n"); sb.append("\t<enterprise-beans>\n"); SAXReader reader = new SAXReader(); reader.setEntityResolver(new EntityResolver()); Document doc = reader.read(new File("classes/META-INF/ejb-jar.xml")); Iterator itr = doc.getRootElement().element("enterprise-beans").elements("session").iterator(); while (itr.hasNext()) { Element entity = (Element) itr.next(); sb.append("\t\t<ejb>\n"); sb.append("\t\t\t<ejb-name>").append(entity.elementText("ejb-name")).append("</ejb-name>\n"); if (entity.elementText("display-name").endsWith("LocalManagerEJB")) { sb.append("\t\t\t<jndi-name>ejb/liferay/").append(entity.elementText("display-name")) .append("Home</jndi-name>\n"); } else { sb.append("\t\t\t<jndi-name>").append(entity.elementText("ejb-name")).append("</jndi-name>\n"); } sb.append("\t\t\t<bean-pool>\n"); sb.append("\t\t\t\t<steady-pool-size>0</steady-pool-size>\n"); sb.append("\t\t\t\t<resize-quantity>60</resize-quantity>\n"); sb.append("\t\t\t\t<max-pool-size>60</max-pool-size>\n"); sb.append("\t\t\t\t<pool-idle-timeout-in-seconds>900</pool-idle-timeout-in-seconds>\n"); sb.append("\t\t\t</bean-pool>\n"); sb.append("\t\t</ejb>\n"); } sb.append("\t</enterprise-beans>\n"); sb.append("</sun-ejb-jar>"); File outputFile = new File("classes/META-INF/sun-ejb-jar.xml"); if (!outputFile.exists() || !FileUtil.read(outputFile).equals(sb.toString())) { FileUtil.write(outputFile, sb.toString()); Logger.info(EJBXMLBuilder.class, outputFile.toString()); } }
From source file:com.liferay.portal.tools.EJBXMLBuilder.java
License:Open Source License
private void _buildWebLogicXML() throws Exception { StringBuffer sb = new StringBuffer(); sb.append("<?xml version=\"1.0\"?>\n"); sb.append(//from w w w .ja va2s .co m "<!DOCTYPE weblogic-ejb-jar PUBLIC \"-//BEA Systems, Inc.//DTD WebLogic 7.0.0 EJB//EN\" \"http://www.bea.com/servers/wls700/dtd/weblogic-ejb-jar.dtd\">\n"); sb.append("\n<weblogic-ejb-jar>\n"); SAXReader reader = new SAXReader(); reader.setEntityResolver(new EntityResolver()); Document doc = reader.read(new File("classes/META-INF/ejb-jar.xml")); Iterator itr = doc.getRootElement().element("enterprise-beans").elements("session").iterator(); while (itr.hasNext()) { Element entity = (Element) itr.next(); sb.append("\t<weblogic-enterprise-bean>\n"); sb.append("\t\t<ejb-name>").append(entity.elementText("ejb-name")).append("</ejb-name>\n"); if (entity.elementText("display-name").endsWith("LocalManagerEJB")) { sb.append("\t\t<local-jndi-name>ejb/liferay/").append(entity.elementText("display-name")) .append("Home</local-jndi-name>\n"); } else { sb.append("\t\t<jndi-name>").append(entity.elementText("ejb-name")).append("</jndi-name>\n"); } sb.append("\t</weblogic-enterprise-bean>\n"); } sb.append("</weblogic-ejb-jar>"); File outputFile = new File("classes/META-INF/weblogic-ejb-jar.xml"); if (!outputFile.exists() || !FileUtil.read(outputFile).equals(sb.toString())) { FileUtil.write(outputFile, sb.toString()); Logger.info(EJBXMLBuilder.class, outputFile.toString()); } }
From source file:com.liferay.portal.tools.EJBXMLBuilder.java
License:Open Source License
private void _buildWebSphereXML() throws Exception { StringBuffer sb = new StringBuffer(); sb.append("<?xml version=\"1.0\"?>\n"); sb.append(//from w w w . j a v a2 s .c om "\n<com.ibm.ejs.models.base.bindings.ejbbnd:EJBJarBinding xmlns:com.ibm.ejs.models.base.bindings.ejbbnd=\"ejbbnd.xmi\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:com.ibm.ejs.models.base.bindings.commonbnd=\"commonbnd.xmi\" xmlns:com.ibm.etools.ejb=\"ejb.xmi\" xmlns:com.ibm.etools.j2ee.common=\"common.xmi\" xmi:version=\"2.0\" xmi:id=\"ejb-jar_ID_Bnd\" currentBackendId=\"CLOUDSCAPE_V50_1\">\n"); sb.append("\t<ejbJar href=\"META-INF/ejb-jar.xml#ejb-jar_ID\" />\n"); SAXReader reader = new SAXReader(); reader.setEntityResolver(new EntityResolver()); Document doc = reader.read(new File("classes/META-INF/ejb-jar.xml")); int sessionCount = 0; int ejbLocalRefCount = 0; Iterator itr1 = doc.getRootElement().element("enterprise-beans").elements("session").iterator(); while (itr1.hasNext()) { Element sessionEl = (Element) itr1.next(); sb.append("\t<ejbBindings xmi:id=\"Session_").append(++sessionCount).append("_Bnd\" jndiName=\""); if (sessionEl.elementText("display-name").endsWith("LocalManagerEJB")) { sb.append("ejb/liferay/").append(sessionEl.elementText("display-name")).append("Home"); } else { sb.append(sessionEl.elementText("ejb-name")); } sb.append("\">\n"); sb.append( "\t\t<enterpriseBean xmi:type=\"com.ibm.etools.ejb:Session\" href=\"META-INF/ejb-jar.xml#Session_") .append(sessionCount).append("\" />\n"); Iterator itr2 = sessionEl.elements("ejb-local-ref").iterator(); while (itr2.hasNext()) { Element ejbLocalRefEl = (Element) itr2.next(); sb.append("\t\t<ejbRefBindings xmi:id=\"EjbRefBinding_").append(++ejbLocalRefCount) .append("\" jndiName=\"").append(ejbLocalRefEl.elementText("ejb-ref-name")).append("\">\n"); sb.append( "\t\t\t<bindingEjbRef xmi:type=\"com.ibm.etools.j2ee.common:EJBLocalRef\" href=\"META-INF/ejb-jar.xml#EjbRef_") .append(ejbLocalRefCount).append("\" />\n"); sb.append("\t\t</ejbRefBindings>\n"); } sb.append("\t</ejbBindings>\n"); } sb.append("</com.ibm.ejs.models.base.bindings.ejbbnd:EJBJarBinding>"); File outputFile = new File("classes/META-INF/ibm-ejb-jar-bnd.xmi"); if (!outputFile.exists() || !FileUtil.read(outputFile).equals(sb.toString())) { FileUtil.write(outputFile, sb.toString()); Logger.info(EJBXMLBuilder.class, outputFile.toString()); } }
From source file:com.liferay.portal.tools.EJBXMLBuilder.java
License:Open Source License
private void _updateEJBXML() throws Exception { File xmlFile = new File("classes/META-INF/ejb-jar.xml"); StringBuffer methodsSB = new StringBuffer(); SAXReader reader = new SAXReader(); reader.setEntityResolver(new EntityResolver()); Document doc = reader.read(xmlFile); Iterator itr = doc.getRootElement().element("enterprise-beans").elements("entity").iterator(); while (itr.hasNext()) { Element entity = (Element) itr.next(); methodsSB.append("\t\t\t<method>\n"); methodsSB.append("\t\t\t\t<ejb-name>" + entity.elementText("ejb-name") + "</ejb-name>\n"); methodsSB.append("\t\t\t\t<method-name>*</method-name>\n"); methodsSB.append("\t\t\t</method>\n"); }//from ww w. ja va 2 s .co m itr = doc.getRootElement().element("enterprise-beans").elements("session").iterator(); while (itr.hasNext()) { Element entity = (Element) itr.next(); methodsSB.append("\t\t\t<method>\n"); methodsSB.append("\t\t\t\t<ejb-name>" + entity.elementText("ejb-name") + "</ejb-name>\n"); methodsSB.append("\t\t\t\t<method-name>*</method-name>\n"); methodsSB.append("\t\t\t</method>\n"); } StringBuffer sb = new StringBuffer(); sb.append("\t<assembly-descriptor>\n"); sb.append("\t\t<method-permission>\n"); sb.append("\t\t\t<unchecked />\n"); sb.append(methodsSB); sb.append("\t\t</method-permission>\n"); sb.append("\t\t<container-transaction>\n"); sb.append(methodsSB); sb.append("\t\t\t<trans-attribute>Required</trans-attribute>\n"); sb.append("\t\t</container-transaction>\n"); sb.append("\t</assembly-descriptor>\n"); String content = FileUtil.read(xmlFile); int x = content.indexOf("<assembly-descriptor>") - 1; int y = content.indexOf("</assembly-descriptor>", x) + 23; if (x < 0) { x = content.indexOf("</ejb-jar>"); y = x; } String newContent = content.substring(0, x) + sb.toString() + content.substring(y, content.length()); if (!content.equals(newContent)) { FileUtil.write(xmlFile, newContent); } }
From source file:com.liferay.portlet.PortletPreferencesSerializer.java
License:Open Source License
public static PortletPreferences fromDefaultXML(String xml) throws PortalException, SystemException { PortletPreferencesImpl prefs = new PortletPreferencesImpl(); if (Validator.isNull(xml)) { return prefs; }/*from w w w.j av a 2 s. co m*/ Map preferences = prefs.getPreferences(); try { Document doc = new SAXReader().read(new StringReader(xml)); Element root = doc.getRootElement(); Iterator itr1 = root.elements("preference").iterator(); while (itr1.hasNext()) { Element prefEl = (Element) itr1.next(); String name = prefEl.elementTextTrim("name"); List values = new ArrayList(); Iterator itr2 = prefEl.elements("value").iterator(); while (itr2.hasNext()) { Element valueEl = (Element) itr2.next(); /*if (valueEl.nodeCount() <= 0) { values.add(valueEl.getText()); } else { values.add(valueEl.node(0).asXML()); }*/ values.add(valueEl.getTextTrim()); } boolean readOnly = GetterUtil.get(prefEl.elementText("read-only"), false); Preference preference = new Preference(name, (String[]) values.toArray(new String[0]), readOnly); preferences.put(name, preference); } return prefs; } catch (DocumentException de) { throw new SystemException(de); } }
From source file:com.litt.core.security.license.gui.ConfigPanel.java
/** * Create the panel./*from ww w . j a va 2s . c o m*/ */ public ConfigPanel(final Gui gui) { GridBagLayout gbl_configPanel = new GridBagLayout(); gbl_configPanel.columnWidths = new int[] { 0, 0, 0, 0 }; gbl_configPanel.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; gbl_configPanel.columnWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE }; gbl_configPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE }; this.setLayout(gbl_configPanel); JLabel label_18 = new JLabel("?"); GridBagConstraints gbc_label_18 = new GridBagConstraints(); gbc_label_18.insets = new Insets(0, 0, 5, 5); gbc_label_18.anchor = GridBagConstraints.EAST; gbc_label_18.gridx = 0; gbc_label_18.gridy = 0; this.add(label_18, gbc_label_18); comboBox_config = new JComboBox(); comboBox_config.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { try { LicenseConfig licenseConfig = (LicenseConfig) e.getItem(); File licenseFile = new File(licenseConfig.getLicenseFilePath()); currentLicenseConfig = licenseConfig; loadLicense(licenseFile); gui.setCurrentLicenseConfig(currentLicenseConfig); } catch (Exception e1) { JOptionPane.showMessageDialog(self, e1.getMessage()); } } } }); GridBagConstraints gbc_comboBox_config = new GridBagConstraints(); gbc_comboBox_config.insets = new Insets(0, 0, 5, 5); gbc_comboBox_config.fill = GridBagConstraints.HORIZONTAL; gbc_comboBox_config.gridx = 1; gbc_comboBox_config.gridy = 0; this.add(comboBox_config, gbc_comboBox_config); JButton button_3 = new JButton("?"); button_3.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { try { comboBox_config.removeAllItems(); File configFile = new File(Gui.HOME_PATH + File.separator + "config.xml"); Document document = XmlUtils.readXml(configFile); Element rootE = document.getRootElement(); List productList = rootE.elements(); for (int i = 0; i < productList.size(); i++) { Element productE = (Element) productList.get(i); String productCode = productE.attributeValue("code"); List customerList = productE.elements(); for (int j = 0; j < customerList.size(); j++) { Element customerE = (Element) customerList.get(j); String customerCode = customerE.attributeValue("code"); LicenseConfig licenseConfig = new LicenseConfig(); licenseConfig.setProductCode(productCode); licenseConfig.setCustomerCode(customerCode); licenseConfig.setLicenseId(customerE.elementText("licenseId")); licenseConfig.setEncryptedLicense(customerE.elementText("encryptedLicense")); licenseConfig.setRootFilePath(Gui.HOME_PATH); licenseConfig.setLicenseFilePath(Gui.HOME_PATH + File.separator + productCode + File.separator + customerCode + File.separator + "license.xml"); licenseConfig.setPriKeyFilePath( Gui.HOME_PATH + File.separator + productCode + File.separator + "private.key"); licenseConfig.setPubKeyFilePath( Gui.HOME_PATH + File.separator + productCode + File.separator + "license.key"); comboBox_config.addItem(licenseConfig); if (i == 0 && j == 0) { File licenseFile = new File(licenseConfig.getLicenseFilePath()); currentLicenseConfig = licenseConfig; loadLicense(licenseFile); gui.setCurrentLicenseConfig(currentLicenseConfig); btnDelete.setEnabled(true); } } } } catch (Exception e1) { e1.printStackTrace(); JOptionPane.showMessageDialog(self, e1.getMessage()); } } }); btnDelete = new JButton(); btnDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (currentLicenseConfig != null) { try { String productCode = currentLicenseConfig.getProductCode(); String customerCode = currentLicenseConfig.getCustomerCode(); //congfig.xml File configFile = new File(Gui.HOME_PATH + File.separator + "config.xml"); Document document = XmlUtils.readXml(configFile); Element customerNode = (Element) document.selectSingleNode( "//product[@code='" + productCode + "']/customer[@code='" + customerCode + "']"); if (customerNode != null) { customerNode.detach(); XmlUtils.writeXml(configFile, document); } // File licensePathFile = new File(currentLicenseConfig.getLicenseFilePath()); if (licensePathFile.exists()) { FileUtils.deleteDirectory(licensePathFile.getParentFile()); } //comboboxitem comboBox_config.removeItemAt(comboBox_config.getSelectedIndex()); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (comboBox_config.getItemCount() <= 0) { btnDelete.setEnabled(false); } } } }); btnDelete.setEnabled(false); btnDelete.setIcon(new ImageIcon(ConfigPanel.class.getResource("/images/icon_delete.png"))); GridBagConstraints gbc_btnDelete = new GridBagConstraints(); gbc_btnDelete.insets = new Insets(0, 0, 5, 0); gbc_btnDelete.gridx = 2; gbc_btnDelete.gridy = 0; add(btnDelete, gbc_btnDelete); GridBagConstraints gbc_button_3 = new GridBagConstraints(); gbc_button_3.insets = new Insets(0, 0, 5, 5); gbc_button_3.gridx = 1; gbc_button_3.gridy = 1; this.add(button_3, gbc_button_3); JLabel lblid = new JLabel("?ID"); GridBagConstraints gbc_lblid = new GridBagConstraints(); gbc_lblid.anchor = GridBagConstraints.EAST; gbc_lblid.insets = new Insets(0, 0, 5, 5); gbc_lblid.gridx = 0; gbc_lblid.gridy = 2; this.add(lblid, gbc_lblid); textField_licenseId = new JTextField(); GridBagConstraints gbc_textField_licenseId = new GridBagConstraints(); gbc_textField_licenseId.insets = new Insets(0, 0, 5, 5); gbc_textField_licenseId.fill = GridBagConstraints.HORIZONTAL; gbc_textField_licenseId.gridx = 1; gbc_textField_licenseId.gridy = 2; this.add(textField_licenseId, gbc_textField_licenseId); textField_licenseId.setColumns(10); JLabel label = new JLabel("?"); GridBagConstraints gbc_label = new GridBagConstraints(); gbc_label.anchor = GridBagConstraints.EAST; gbc_label.insets = new Insets(0, 0, 5, 5); gbc_label.gridx = 0; gbc_label.gridy = 3; add(label, gbc_label); comboBox_licenseType = new JComboBox(MapComboBoxModel.getLicenseTypeOptions().toArray()); GridBagConstraints gbc_comboBox_licenseType = new GridBagConstraints(); gbc_comboBox_licenseType.insets = new Insets(0, 0, 5, 5); gbc_comboBox_licenseType.fill = GridBagConstraints.HORIZONTAL; gbc_comboBox_licenseType.gridx = 1; gbc_comboBox_licenseType.gridy = 3; add(comboBox_licenseType, gbc_comboBox_licenseType); JLabel label_23 = new JLabel("???"); GridBagConstraints gbc_label_23 = new GridBagConstraints(); gbc_label_23.anchor = GridBagConstraints.EAST; gbc_label_23.insets = new Insets(0, 0, 5, 5); gbc_label_23.gridx = 0; gbc_label_23.gridy = 4; this.add(label_23, gbc_label_23); textField_productName = new JTextField(); GridBagConstraints gbc_textField_productName = new GridBagConstraints(); gbc_textField_productName.insets = new Insets(0, 0, 5, 5); gbc_textField_productName.fill = GridBagConstraints.HORIZONTAL; gbc_textField_productName.gridx = 1; gbc_textField_productName.gridy = 4; this.add(textField_productName, gbc_textField_productName); textField_productName.setColumns(10); JLabel label_24 = new JLabel("???"); GridBagConstraints gbc_label_24 = new GridBagConstraints(); gbc_label_24.anchor = GridBagConstraints.EAST; gbc_label_24.insets = new Insets(0, 0, 5, 5); gbc_label_24.gridx = 0; gbc_label_24.gridy = 5; this.add(label_24, gbc_label_24); textField_companyName = new JTextField(); GridBagConstraints gbc_textField_companyName = new GridBagConstraints(); gbc_textField_companyName.insets = new Insets(0, 0, 5, 5); gbc_textField_companyName.fill = GridBagConstraints.HORIZONTAL; gbc_textField_companyName.gridx = 1; gbc_textField_companyName.gridy = 5; this.add(textField_companyName, gbc_textField_companyName); textField_companyName.setColumns(10); JLabel label_25 = new JLabel("??"); GridBagConstraints gbc_label_25 = new GridBagConstraints(); gbc_label_25.anchor = GridBagConstraints.EAST; gbc_label_25.insets = new Insets(0, 0, 5, 5); gbc_label_25.gridx = 0; gbc_label_25.gridy = 6; this.add(label_25, gbc_label_25); textField_customerName = new JTextField(); GridBagConstraints gbc_textField_customerName = new GridBagConstraints(); gbc_textField_customerName.insets = new Insets(0, 0, 5, 5); gbc_textField_customerName.fill = GridBagConstraints.HORIZONTAL; gbc_textField_customerName.gridx = 1; gbc_textField_customerName.gridy = 6; this.add(textField_customerName, gbc_textField_customerName); textField_customerName.setColumns(10); JLabel label_26 = new JLabel(""); GridBagConstraints gbc_label_26 = new GridBagConstraints(); gbc_label_26.anchor = GridBagConstraints.EAST; gbc_label_26.insets = new Insets(0, 0, 5, 5); gbc_label_26.gridx = 0; gbc_label_26.gridy = 7; this.add(label_26, gbc_label_26); textField_version = new JTextField(); GridBagConstraints gbc_textField_version = new GridBagConstraints(); gbc_textField_version.insets = new Insets(0, 0, 5, 5); gbc_textField_version.fill = GridBagConstraints.HORIZONTAL; gbc_textField_version.gridx = 1; gbc_textField_version.gridy = 7; this.add(textField_version, gbc_textField_version); textField_version.setColumns(10); JLabel label_27 = new JLabel(""); GridBagConstraints gbc_label_27 = new GridBagConstraints(); gbc_label_27.insets = new Insets(0, 0, 5, 5); gbc_label_27.gridx = 0; gbc_label_27.gridy = 8; this.add(label_27, gbc_label_27); datePicker_expiredDate = new DatePicker(new Date(), "yyyy-MM-dd", null, null); //datePicker_expiredDate.setTimePanleVisible(false); GridBagConstraints gbc_datePicker_expiredDate = new GridBagConstraints(); gbc_datePicker_expiredDate.anchor = GridBagConstraints.WEST; gbc_datePicker_expiredDate.insets = new Insets(0, 0, 5, 5); gbc_datePicker_expiredDate.gridx = 1; gbc_datePicker_expiredDate.gridy = 8; this.add(datePicker_expiredDate, gbc_datePicker_expiredDate); JButton button_5 = new JButton(""); button_5.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (currentLicenseConfig != null) { try { File priKeyFile = new File(currentLicenseConfig.getPriKeyFilePath()); File licenseFile = new File(currentLicenseConfig.getLicenseFilePath()); //?? License license = new License(); license.setLicenseId(textField_licenseId.getText()); license.setLicenseType( ((MapComboBoxModel) comboBox_licenseType.getSelectedItem()).getValue().toString()); license.setProductName(textField_productName.getText()); license.setCompanyName(textField_companyName.getText()); license.setCustomerName(textField_customerName.getText()); license.setVersion(Version.parseVersion(textField_version.getText())); license.setCreateDate(new Date()); license.setExpiredDate(Utility.parseDate(datePicker_expiredDate.getText())); //???? DigitalSignatureTool utils = new DigitalSignatureTool("DSA"); utils.readPriKey(priKeyFile.getAbsolutePath()); //?? String signedData = utils.sign(license.toString()); //?????? license.setSignature(signedData); LicenseManager.writeLicense(license, licenseFile); //config.xml String licenseContent = XmlUtils.readXml(licenseFile).asXML(); //DES ISecurity security = new DESTool(currentLicenseConfig.getLicenseId(), Algorithm.BLOWFISH); licenseContent = security.encrypt(licenseContent); txt_encryptContent.setText(licenseContent); currentLicenseConfig.setEncryptedLicense(licenseContent); System.out.println(licenseContent); File configFile = new File(Gui.HOME_PATH + File.separator + "config.xml"); XMLConfiguration config = new XMLConfiguration(configFile); config.setAutoSave(true); config.setProperty("product.customer.encryptedLicense", licenseContent); //??zip? File customerPath = licenseFile.getParentFile(); //???license????? File licensePath = new File(customerPath.getParent(), "license"); if (!licensePath.exists() && !licensePath.isDirectory()) { licensePath.mkdir(); } else { FileUtils.cleanDirectory(licensePath); } //? FileUtils.copyDirectory(customerPath, licensePath); String currentTime = FormatDateTime.formatDateTimeNum(new Date()); ZipUtils.zip(licensePath, new File(licensePath.getParentFile(), currentLicenseConfig.getCustomerCode() + "-" + currentTime + ".zip")); //license FileUtils.deleteDirectory(licensePath); JOptionPane.showMessageDialog(self, "??"); } catch (Exception e1) { e1.printStackTrace(); JOptionPane.showMessageDialog(self, e1.getMessage()); } } else { JOptionPane.showMessageDialog(self, "???"); } } }); GridBagConstraints gbc_button_5 = new GridBagConstraints(); gbc_button_5.insets = new Insets(0, 0, 5, 5); gbc_button_5.gridx = 1; gbc_button_5.gridy = 9; this.add(button_5, gbc_button_5); JScrollPane scrollPane = new JScrollPane(); GridBagConstraints gbc_scrollPane = new GridBagConstraints(); gbc_scrollPane.insets = new Insets(0, 0, 0, 5); gbc_scrollPane.fill = GridBagConstraints.BOTH; gbc_scrollPane.gridx = 1; gbc_scrollPane.gridy = 10; this.add(scrollPane, gbc_scrollPane); txt_encryptContent = new JTextArea(); txt_encryptContent.setLineWrap(true); scrollPane.setViewportView(txt_encryptContent); // txt_encryptContent = new JTextArea(20, 20); // GridBagConstraints gbc_6 = new GridBagConstraints(); // gbc_6.gridx = 1; // gbc_6.gridy = 10; // this.add(txt_encryptContent, gbc_6); }
From source file:com.love320.templateparser.factory.impl.LabelBeanFactoryImpl.java
License:Apache License
@Override public LabelBean get(String labelName) { LabelBean labelBean = new LabelBean();//? //??xml?//from w w w .j av a 2 s . c o m Element labelElement = (Element) DOCROOT.selectSingleNode("/labels/label[@name='" + labelName + "']"); if (labelElement != null) { //? xml? String name = labelElement.attributeValue("name"); String parameters = labelElement.elementText("parameters"); String template = labelElement.elementText("template"); String bean = labelElement.elementText("bean"); String note = labelElement.elementText("note"); //LabelBean? labelBean.setName(name); labelBean.setParameters(parameters); labelBean.setTemplate(template); labelBean.setBean(bean); labelBean.setNote(note); } else { labelBean.setName(labelName); } //? /*System.out.println(labelBean.getName()); System.out.println(labelBean.getParameters()); System.out.println(labelBean.getTemplate()); System.out.println(labelBean.getBean()); System.out.println(labelBean.getNote());*/ return labelBean; }
From source file:com.love320.templateparser.label.impl.LabelBeanDaoImpl.java
License:Apache License
private boolean upSeting(Element labelElement, LabelBean labelBean) { //? Element?//from w w w.j a va 2s. c om String name = labelElement.attributeValue("name"); String parameters = labelElement.elementText("parameters"); String template = labelElement.elementText("template"); String bean = labelElement.elementText("bean"); String note = labelElement.elementText("note"); //LabelBean? labelBean.setName(name); labelBean.setParameters(parameters); labelBean.setTemplate(template); labelBean.setBean(bean); labelBean.setNote(note); return true; }
From source file:com.mingsoft.weixin.util.XmlUtils.java
License:Open Source License
/** * ?xml??document??key?</br> xml?</br> * //from ww w . ja v a 2s . c om * @param str * * @param key * ?? * @param sonKey ??? * @return ??stringnull */ public static String getString(String str, String key, String sonKey) { try { Document document = DocumentHelper.parseText(str); Element root = document.getRootElement(); for (Iterator<?> i = root.elementIterator(key); i.hasNext();) { Element foo = (Element) i.next(); return foo.elementText(sonKey); } } catch (Exception e) { e.printStackTrace(); LOG.debug("Exception?xml:" + str); LOG.debug("Exception?key:" + key); } return null; }
From source file:com.noterik.bart.fs.action.GenericIndexAction.java
License:Open Source License
/** * Create XML for an index/* ww w. j a v a 2 s.co m*/ * * @param typeContent * @param objectUri * @param objectDetails * @param collectionDetails * @param iConfig */ private static void makeType(Element typeContent, String objectUri, Map<String, Object> objectDetails, Map<String, Object> collectionDetails, IndexConfig iConfig) { // create new type Document typeDocument = DocumentHelper.createDocument(); Element fsxml = typeDocument.addElement("fsxml"); Element type = fsxml.addElement(iConfig.getIndexType()); String objectType = iConfig.getIndexObject(); // add refer to original object Element referObject = type.addElement(objectType); referObject.addAttribute("id", "1"); referObject.addAttribute("referid", objectUri); // add refer to original collection Element referCollectionObject = type.addElement("collection" + objectType); referCollectionObject.addAttribute("id", "1"); String collectionObject = (String) collectionDetails.get("object"); collectionObject = collectionObject.substring(0, collectionObject.length() - 1); referCollectionObject.addAttribute("referid", (String) collectionObject); Element properties = type.addElement("properties"); //add standard properties properties.addElement(objectType).addText((String) collectionDetails.get("object")); properties.addElement(objectType + "uri").addText(objectUri + "/"); properties.addElement("collection").addText((String) collectionDetails.get("collection")); properties.addElement(objectType + "title").addText((String) objectDetails.get(objectType + "title")); properties.addElement(objectType + "description") .addText((String) objectDetails.get(objectType + "description")); properties.addElement(objectType + "screenshot") .addText((String) objectDetails.get(objectType + "screenshot")); //properties.addElement(objectType+"type").addText((String) objectDetails.get(objectType+"type")); //properties.addElement(objectType+"author").addText((String) objectDetails.get(objectType+"author")); //properties.addElement(objectType+"copyright").addText((String) objectDetails.get(objectType+"copyright")); //properties.addElement(objectType+"website").addText((String) objectDetails.get(objectType+"website")); //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(objectType + "duration") || item.equals(objectType + "theme") || item.equals(objectType + "location") || item.equals(objectType + "date") || item.equals(objectType + "date_original") || item.equals(objectType + "public") || item.equals("sponsor")) { properties.addElement(item).addText((String) objectDetails.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) objectDetails.get(objectType), start, (String) objectDetails.get(objectType + "screenshot"))); } else if (item.equals("rank")) { properties.addElement(item) .addText(String.valueOf(getRankBasedOnLockmode((String) objectDetails.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) objectDetails.get(objectType), "location", start, duration, new String[] { "name" })); } else if (item.equals("dates")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "date", start, duration, new String[] { "start", "end" })); } else if (item.equals("keywords")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "keyword", start, duration, new String[] { "name" })); } else if (item.equals("persons")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "person", start, duration, new String[] { "name" })); } else if (item.equals("periods")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "period", start, duration, new String[] { "name" })); } else if (item.equals("speakers")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "speakers", start, duration, new String[] { "firstname", "lastname", "organization" })); } else if (item.equals("topics")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "topics", start, duration, new String[] { "name" })); } else if (item.equals("peercomments")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "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(objectType + iConfig.getIndexType())) { properties.addElement(item).addText(getTypeUri(typeContent, objectUri, iConfig)); } else if (item.equals("bookmark")) { properties.addElement(item).addText(getType((Document) objectDetails.get(objectType), "bookmark", 0.0, 86400000.0, new String[] { "title", "description", "creator" })); } else if (item.equals("webtv_item_id") || item.equals(objectType + "livestate")) { properties.addElement(item).addText((String) objectDetails.get(item)); } else if (item.equals(objectType + "status") || item.equals(objectType + "theme") || item.equals(objectType + "time") || item.equals(objectType + "type")) { properties.addElement(item).addText((String) objectDetails.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); }