private void openIfRequired() throws IOException { String state = Environment.getExternalStorageState(); if (mSerializer == null) { String fileName = mReportFile; if (mMultiFile) { fileName = fileName.replace("$(suite)", "test"); } if (mReportDir == null) { if (Environment.MEDIA_MOUNTED.equals(state) && !Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { File f = mContext.getExternalFilesDir("testng"); mOutputStream = new FileOutputStream(new File(f, fileName)); } else { mOutputStream = mTargetContext.openFileOutput(fileName, 0); } } else { mOutputStream = new FileOutputStream(new File(mReportDir, fileName)); } mSerializer = Xml.newSerializer(); mSerializer.setOutput(mOutputStream, ENCODING_UTF_8); mSerializer.startDocument(ENCODING_UTF_8, true); if (!mMultiFile) { mSerializer.startTag("", TAG_SUITES); } } }
private static void serializeRoutingInfo(XmlSerializer paramXmlSerializer, String paramString) throws IOException { if (StringUtils.isEmpty(paramString)) paramString = ""; paramXmlSerializer.startTag("http://schemas.google.com/gsync/data", "routingInfo"); paramXmlSerializer.text(paramString); paramXmlSerializer.endTag("http://schemas.google.com/gsync/data", "routingInfo"); }
@Override public void serializeContent(XmlSerializer serializer) throws IOException { if (isEmpty()) return; SerializerUtils.addTextTag(serializer, VCardProperty.FN.toString(), getFormattedName()); serializer.startTag(null, N_NAME); for (Entry<NameProperty, String> entry : name.entrySet()) SerializerUtils.addTextTag(serializer, entry.getKey().toString(), entry.getValue()); serializer.endTag(null, N_NAME); for (Entry<VCardProperty, String> entry : properties.entrySet()) if (entry.getKey() != VCardProperty.FN) SerializerUtils.addTextTag(serializer, entry.getKey().toString(), entry.getValue()); for (Photo photo : photos) photo.serialize(serializer); for (Address address : addresses) address.serialize(serializer); for (Label label : labels) label.serialize(serializer); for (Telephone telephone : telephones) telephone.serialize(serializer); for (Email email : emails) email.serialize(serializer); for (Logo logo : logos) logo.serialize(serializer); for (Sound sound : sounds) sound.serialize(serializer); for (Geo geo : geos) geo.serialize(serializer); for (Organization organization : organizations) organization.serialize(serializer); if (!categories.isEmpty()) { serializer.startTag(null, CATEGORIES_NAME); for (String keyword : categories) SerializerUtils.addTextTag(serializer, KEYWORD_NAME, keyword); serializer.endTag(null, CATEGORIES_NAME); } if (classification != null) SerializerUtils.addTextTag(serializer, CLASS_NAME, classification.toString()); for (Key key : keys) key.serialize(serializer); }
private void writeDataElement(XmlSerializer xml, String name, SimpleData value, int depth) throws IOException { String elemName = null; String text = null; if (value instanceof TagData) { elemName = TAG_ELEM; } else if (value instanceof DateData) { elemName = DATE_ELEM; Date d = ((DateData) value).getValue(); if (d != null) text = XMLUtils.saveDate(d); } else if (value instanceof NumberData) { elemName = NUMBER_ELEM; text = numberFormat.format(((NumberData) value).getDouble()); } else { elemName = STRING_ELEM; text = value.toString(); } if (elemName != null) { indent(xml, depth); xml.startTag(null, elemName); xml.attribute(null, NAME_ATTR, name); if (text != null) xml.text(text); xml.endTag(null, elemName); xml.ignorableWhitespace(NEWLINE); } }
private void end(String tagName) throws IOException { xml.endTag(null, tagName); xml.text("\n"); for (int i = 1; i < xml.getDepth(); i++) { xml.text("\t"); } }
private void addCreateStructure(boolean b) throws IllegalArgumentException, IllegalStateException, IOException { serializer.startTag("", "create_structure"); serializer.attribute("", "type", "boolean"); serializer.text(String.valueOf(b)); serializer.endTag("", "create_structure"); }
/** * Creates a new DomElement object. * * @param contentType_QNAME the content type_ qname * @param class1 the class1 * @param object the object * @param value the value * @return the element */ private String createElement( String contentType_QNAME, Class<?> class1, Object object, Object value) { if (value != null) { StringWriter writer = new StringWriter(); try { XmlSerializer serializer = XML_SERIALIZER_FACTORY.newSerializer(); serializer.setOutput(writer); serializer = serializer.startTag(null, contentType_QNAME); if (class1.equals(InviteConnectType.class)) { XppUtils.setElementValue(serializer, ((InviteConnectType) value).value()); } else if (class1.equals(NetworkUpdateReturnType.class)) { XppUtils.setElementValue(serializer, ((NetworkUpdateReturnType) value).value()); } else if (class1.equals(NetworkUpdateContentType.class)) { XppUtils.setElementValue(serializer, ((NetworkUpdateContentType) value).value()); } else { XppUtils.setElementValue(serializer, String.valueOf(value)); } serializer.endTag(null, contentType_QNAME); serializer.flush(); } catch (Exception e) { LOG.log(Level.SEVERE, "An error occurred while creating xml content.", e); } return writer.toString(); } else { return null; } }
private void addAuthenticateByKey(boolean authenticateByKey) throws IllegalArgumentException, IllegalStateException, IOException { serializer.startTag("", "authenticate_by_key"); serializer.text(authenticateByKey ? "true" : "false"); serializer.endTag("", "authenticate_by_key"); }
private void addUseActiveMode(boolean useActiveMode) throws IllegalArgumentException, IllegalStateException, IOException { serializer.startTag("", "use_active_mode"); serializer.text(useActiveMode ? "true" : "false"); serializer.endTag("", "use_active_mode"); }
private void addPreReleaseHook(String preReleaseHook) throws IllegalArgumentException, IllegalStateException, IOException { serializer.startTag("", "pre_release_hook"); serializer.text(preReleaseHook); serializer.endTag("", "pre_release_hook"); }
private void addUseFeat(boolean useFeat) throws IllegalArgumentException, IllegalStateException, IOException { serializer.startTag("", "use_feat"); serializer.text(useFeat ? "true" : "false"); serializer.endTag("", "use_feat"); }
private void addDeployFromScratch(boolean deployFromScratch) throws IllegalArgumentException, IllegalStateException, IOException { serializer.startTag("", "deploy_from_scratch"); serializer.text(deployFromScratch ? "true" : "false"); serializer.endTag("", "deploy_from_scratch"); }
public String createModifyServerXML(Server server) throws IllegalArgumentException, IllegalStateException, IOException { serializer = Xml.newSerializer(); writer = new StringWriter(); serializer.setOutput(writer); serializer.startDocument("UTF-8", null); serializer.startTag("", "release_server"); // TODO refactor for better performance addName(server.getName()); addLocalPath(server.getLocalPath()); addRemotePath(server.getRemotePath()); addRemoteAddr(server.getRemoteAddr()); addProtocol(server.getProtocol()); addPort(server.getPort()); addLogin(server.getLogin()); addPassword(server.getPassword()); addUseActiveMode(server.isUseActiveMode()); addAuthenticateByKey(server.isAuthenticateByKey()); addUseFeat(server.isUseFeat()); addPreReleaseHook(server.getPreReleaseHook()); addPostReleaseHook(server.getPostReleaseHook()); serializer.endTag("", "release_server"); serializer.endDocument(); return writer.toString(); }
public String createNewUserXML( String login, String firstName, String lastName, String email, String timezone, boolean admin, String password) throws IllegalArgumentException, IllegalStateException, IOException { serializer = Xml.newSerializer(); writer = new StringWriter(); serializer.setOutput(writer); serializer.startDocument("UTF-8", null); serializer.startTag("", "user"); addLogin(login); addFirstName(firstName); addLastName(lastName); addEmail(email); addTimezone(timezone); addAdmin(admin ? "1" : ""); addPassword(password); serializer.endTag("", "user"); serializer.endDocument(); return writer.toString(); }
private void addUserId(String userId) throws IllegalArgumentException, IllegalStateException, IOException { serializer.startTag("", "user-id"); serializer.attribute("", "type", "integer"); serializer.text(String.valueOf(userId)); serializer.endTag("", "user-id"); }
private void addPort(int port) throws IllegalArgumentException, IllegalStateException, IOException { serializer.startTag("", "port"); serializer.text(String.valueOf(port)); serializer.endTag("", "port"); }
private void addAdmin(String admin) throws IllegalArgumentException, IllegalStateException, IOException { serializer.startTag("", "admin"); serializer.text(admin); serializer.endTag("", "admin"); }
private void addProtocol(String protocol) throws IllegalArgumentException, IllegalStateException, IOException { serializer.startTag("", "protocol"); serializer.text(protocol); serializer.endTag("", "protocol"); }
private void addRevision(String revId) throws IllegalArgumentException, IllegalStateException, IOException { serializer.startTag("", "revision"); // serializer.attribute("", "type", "integer"); serializer.text(revId); serializer.endTag("", "revision"); }
private void addRemotePath(String remotePath) throws IllegalArgumentException, IllegalStateException, IOException { serializer.startTag("", "remote_path"); serializer.text(remotePath); serializer.endTag("", "remote_path"); }
public String buildFormSubmissionXMLString(String formName, Long recordId) { try { Document document = getXMLModelTemplateForFormName(formName); XmlSerializer serializer = Xml.newSerializer(); StringWriter writer = new StringWriter(); serializer.setOutput(writer); serializer.startDocument("UTF-8", true); // <model><instance> Element el = (Element) document.getElementsByTagName("model").item(0).getFirstChild(); NodeList entries = el.getChildNodes(); int num = entries.getLength(); for (int i = 0; i < num; i++) { Element node = (Element) entries.item(i); writeXML(node, serializer, recordId); } serializer.endDocument(); String xml = writer.toString(); // xml = xml.replaceAll("<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>","");//56 // !!!this ain't working xml = xml.substring(56); System.out.println(xml); return xml; } catch (Exception e) { e.printStackTrace(); } return ""; }
private void addLocalPath(String localPath) throws IllegalArgumentException, IllegalStateException, IOException { serializer.startTag("", "local_path"); serializer.text(localPath); serializer.endTag("", "local_path"); }
private String serialize(Element e, int intent) { try { XmlSerializer s = Xml.newSerializer(); StringWriter sw = new StringWriter(); s.setOutput(sw); s.startDocument("utf-8", null); String spaces = null; if (intent > 0) { char[] chars = new char[intent]; Arrays.fill(chars, ' '); spaces = new String(chars); } serialize(root, s, 0, spaces); s.endDocument(); return sw.toString(); } catch (Exception ex) { ex.printStackTrace(); } return null; }
private void addIsAutomatic(boolean automatic) throws IllegalArgumentException, IllegalStateException, IOException { serializer.startTag("", "automatic"); serializer.text(automatic ? "true" : "false"); serializer.endTag("", "automatic"); }
public void serializeToXml(XmlSerializer serializer, ResResource res) throws IOException, AndrolibException { serializer.startTag(null, "item"); serializer.attribute(null, "type", res.getResSpec().getType().getName()); serializer.attribute(null, "name", res.getResSpec().getName()); serializer.endTag(null, "item"); }
private void addDeploymentAccess(boolean deploymentAccess) throws IllegalArgumentException, IllegalStateException, IOException { serializer.startTag("", "full-deployments-access"); serializer.attribute("", "type", "boolean"); serializer.text(String.valueOf(deploymentAccess)); serializer.endTag("", "full-deployments-access"); }
@Override public void startTest(Test test) { try { if (test instanceof TestCase) { TestCase testCase = TestCase.class.cast(test); if (currentTestCase == null || testCase.getClass() != currentTestCase.getClass()) { // If this is the first test or different test case class is passed, // close last <testsuite> and start new <testsuite>. if (currentTestCase != null) { // <testsuite> has been started already so close it. serializer.endTag(NS_DEFAULT, TAG_TESTSUITE); } serializer.startTag(NS_DEFAULT, TAG_TESTSUITE); serializer.attribute(NS_DEFAULT, ATTR_NAME, testCase.getClass().getName()); } serializer.startTag(NS_DEFAULT, TAG_TESTCASE); serializer.attribute(NS_DEFAULT, ATTR_NAME, testCase.getName()); currentTestCase = testCase; testCaseStartTime = System.currentTimeMillis(); isTimeAppended = false; } else { MozcLog.e("Unextected type; " + test.getClass().getCanonicalName()); } } catch (IOException e) { MozcLog.e(e.getMessage(), e); } }
private void addRepoReadAccess(boolean repoRead) throws IllegalArgumentException, IllegalStateException, IOException { serializer.startTag("", "read"); serializer.attribute("", "type", "boolean"); serializer.text(String.valueOf(repoRead)); serializer.endTag("", "read"); }
private static void addTag(XmlSerializer serializer, String key, String value) throws IOException { serializer.startTag(null, "tag"); serializer.attribute(null, "k", key); serializer.attribute(null, "v", value); serializer.endTag(null, "tag"); }
void writeBookmark2_LabelXml(XmlSerializer xml, int bookmark2_relId, int label_relId) throws IOException { xml.startTag(null, Bookmark2_Label.XMLTAG_Bookmark2_Label); xml.attribute(null, Bookmark2_Label.XMLATTR_bookmark2_relId, String.valueOf(bookmark2_relId)); xml.attribute(null, Bookmark2_Label.XMLATTR_label_relId, String.valueOf(label_relId)); xml.endTag(null, Bookmark2_Label.XMLTAG_Bookmark2_Label); }